Top Description Fields Constructors Methods
tools.jackson.databind.ser.std

public abstract Class StdSerializer<T>

extends ValueSerializer<T>
implements JsonFormatVisitable
Class Inheritance
All Implemented Interfaces
tools.jackson.databind.jsonFormatVisitors.JsonFormatVisitable
Known Direct Subclasses
tools.jackson.databind.ser.std.ToEmptyObjectSerializer, tools.jackson.databind.ser.std.ToStringSerializerBase, tools.jackson.databind.ext.DOMSerializer, tools.jackson.databind.ext.QNameSerializer, tools.jackson.databind.ext.XMLGregorianCalendarSerializer, tools.jackson.databind.ext.javatime.ser.JSR310SerializerBase, tools.jackson.databind.ext.jdk8.DoubleStreamSerializer, tools.jackson.databind.ext.jdk8.IntStreamSerializer, tools.jackson.databind.ext.jdk8.Jdk8StreamSerializer, tools.jackson.databind.ext.jdk8.LongStreamSerializer, tools.jackson.databind.ser.bean.BeanSerializerBase, tools.jackson.databind.ser.impl.FailingSerializer, tools.jackson.databind.ser.impl.UnsupportedTypeSerializer, tools.jackson.databind.ser.jackson.JacksonSerializableSerializer, tools.jackson.databind.ser.jackson.RawSerializer, tools.jackson.databind.ser.jackson.TokenBufferSerializer, tools.jackson.databind.ser.jdk.ByteArraySerializer, tools.jackson.databind.ser.jdk.JDKArraySerializers.CharArraySerializer, tools.jackson.databind.ser.jdk.JDKArraySerializers.BinaryFloatArraySerializer, tools.jackson.databind.ser.jdk.JDKArraySerializers.BinaryDoubleArraySerializer, tools.jackson.databind.ser.jdk.JDKKeySerializers.Default, tools.jackson.databind.ser.jdk.JDKKeySerializers.Dynamic, tools.jackson.databind.ser.jdk.JDKKeySerializers.StringKeySerializer, tools.jackson.databind.ser.jdk.JDKKeySerializers.EnumKeySerializer, tools.jackson.databind.ser.jdk.JDKStringLikeSerializer, tools.jackson.databind.ser.jdk.MapEntryAsPOJOSerializer, tools.jackson.databind.ser.jdk.StaticListSerializerBase, tools.jackson.databind.ser.std.NullSerializer, tools.jackson.databind.ser.std.StdContainerSerializer, tools.jackson.databind.ser.std.StdDelegatingSerializer, tools.jackson.databind.ser.std.StdDynamicSerializer, tools.jackson.databind.ser.std.StdScalarSerializer
Imports
java.io.IOException, java.lang.reflect.InvocationTargetException, java.util.Collection, .IdentityHashMap, .Map, com.fasterxml.jackson.annotation.JsonFormat, .JsonInclude, tools.jackson.core.*, .JsonParser.NumberType, tools.jackson.core.exc.JacksonIOException, tools.jackson.databind.*, tools.jackson.databind.annotation.JacksonStdImpl, tools.jackson.databind.introspect.AnnotatedMember, tools.jackson.databind.jsonFormatVisitors.*, tools.jackson.databind.node.JsonNodeFactory, .ObjectNode, tools.jackson.databind.ser.FilterProvider, .PropertyFilter, tools.jackson.databind.util.ClassUtil, .Converter

Base class used by all standard serializers, and can also be used for custom serializers (in fact, this is the recommended base class to use).

Field Summary

Modifier and TypeField and Description
protected final Class<?>
_handledType

Nominal type supported, usually declared type of property for which serializer is used.

private static final Object
KEY_CONTENT_CONVERTER_LOCK

Key used for storing a lock object to prevent infinite recursion when constructing converting serializers.

Constructor Summary

AccessConstructor and Description
protected
protected
protected
StdSerializer(Class<?> t, boolean dummy)
Deprecated

Alternate constructor that is (alas!) needed to work around kinks of generic type handling

protected

Method Summary

Modifier and TypeMethod and Description
private ValueSerializer<?>
protected static final boolean
protected static final boolean
protected JacksonException
public void
protected void
acceptJsonFormatVisitorForBinary(JsonFormatVisitorWrapper visitor, JavaType typeHint)

Helper method for handling Binary values: typically serialized as Base64-encoded data (in textual formats) or native binary (binary formats).

protected ObjectNode
protected ObjectNode
createSchemaNode(String type, boolean isOptional)

protected ValueSerializer<?>
findAnnotatedContentSerializer(SerializationContext serializers, BeanProperty property)

Convenience method for finding out possibly configured content value serializer.

protected ValueSerializer<?>
findContextualConvertingSerializer(SerializationContext provider, BeanProperty prop, ValueSerializer<?>
(optional) configured content serializer if one already exists.
existingSerializer
)

Helper method that can be used to see if specified property has annotation indicating that a converter is to be used for contained values (contents of structured types; array/List/Map values)

protected Boolean
findFormatFeature(SerializationContext provider, BeanProperty prop, Class<?>
Type (erased) used for finding default format settings, if any
typeForDefaults
,
JsonFormat.Feature feat)

Convenience method that uses findFormatOverrides to find possible defaults and/of overrides, and then calls JsonFormat.Value.getFeature(...) to find whether that feature has been specifically marked as enabled or disabled.

protected JsonFormat.Value
findFormatOverrides(SerializationContext provider, BeanProperty prop, Class<?>
Type (erased) used for finding default format settings, if any
typeForDefaults
)

Helper method that may be used to find if this deserializer has specific JsonFormat settings, either via property, or through type-specific defaulting.

protected JsonInclude.Value
findIncludeOverrides(SerializationContext provider, BeanProperty prop, Class<?> typeForDefaults)

protected PropertyFilter
findPropertyFilter(SerializationContext provider, Object filterId, Object valueToFilter)

Helper method used to locate filter that is needed, based on filter id this serializer was constructed with.

public Class<?>
handledType()

Overrides tools.jackson.databind.ValueSerializer.handledType.

Method for accessing type of Objects this serializer can handle.

protected boolean
isDefaultSerializer(ValueSerializer<?> serializer)

Method that can be called to determine if given serializer is the default serializer Jackson uses; as opposed to a custom serializer installed by a module or calling application.

public abstract void
serialize(T value, JsonGenerator gen, SerializationContext provider)

Implements abstract tools.jackson.databind.ValueSerializer.serialize.

Method that can be called to ask implementation to serialize values of type this serializer handles.

protected void
visitArrayFormat(JsonFormatVisitorWrapper visitor, JavaType typeHint, ValueSerializer<?> itemSerializer, JavaType itemType)

protected void
protected void
visitFloatFormat(JsonFormatVisitorWrapper visitor, JavaType typeHint, JsonParser.NumberType numberType)

Helper method that calls necessary visit method(s) to indicate that the underlying JSON type is a floating-point JSON number.

protected void
visitIntFormat(JsonFormatVisitorWrapper visitor, JavaType typeHint, JsonParser.NumberType numberType)

Helper method that calls necessary visit method(s) to indicate that the underlying JSON type is JSON Integer number.

protected void
visitIntFormat(JsonFormatVisitorWrapper visitor, JavaType typeHint, JsonParser.NumberType numberType, JsonValueFormat format)

Helper method that calls necessary visit method(s) to indicate that the underlying JSON type is JSON Integer number, but that there is also a further format restriction involved.

protected void
visitStringFormat(JsonFormatVisitorWrapper visitor, JavaType typeHint)

Helper method that calls necessary visit method(s) to indicate that the underlying JSON type is JSON String.

protected void
visitStringFormat(JsonFormatVisitorWrapper visitor, JavaType typeHint, JsonValueFormat format)

Helper method that calls necessary visit method(s) to indicate that the underlying JSON type is JSON String, but that there is a more refined logical type

public void
wrapAndThrow(SerializationContext ctxt, Throwable t, Object bean, String fieldName)

Method that will modify caught exception (passed in as argument) as necessary to include reference information, and to ensure it is a subtype of JacksonException, or an unchecked exception.

public void
Inherited from tools.jackson.databind.ValueSerializer:
createContextualgetDelegateeisEmptyisUnwrappingSerializerpropertiesreplaceDelegateeresolveserializeWithTypeunwrappingSerializerusesObjectIdwithFilterIdwithFormatOverrideswithIgnoredProperties

Field Detail

_handledTypeback to summary
protected final Class<?> _handledType

Nominal type supported, usually declared type of property for which serializer is used.

KEY_CONTENT_CONVERTER_LOCKback to summary
private static final Object KEY_CONTENT_CONVERTER_LOCK

Key used for storing a lock object to prevent infinite recursion when constructing converting serializers.

Constructor Detail

StdSerializerback to summary
protected StdSerializer(Class<?> t)
StdSerializerback to summary
protected StdSerializer(JavaType type)
StdSerializerback to summary
protected StdSerializer(Class<?> t, boolean dummy)

Deprecated

Alternate constructor that is (alas!) needed to work around kinks of generic type handling

Annotations
@Deprecated
StdSerializerback to summary
protected StdSerializer(StdSerializer<?> src)

Method Detail

_findConvertingContentSerializerback to summary
private ValueSerializer<?> _findConvertingContentSerializer(SerializationContext provider, AnnotationIntrospector intr, BeanProperty prop, ValueSerializer<?> existingSerializer)
_neitherNullback to summary
protected static final boolean _neitherNull(Object a, Object b)
_nonEmptyback to summary
protected static final boolean _nonEmpty(Collection<?> c)
_wrapIOFailureback to summary
protected JacksonException _wrapIOFailure(SerializationContext ctxt, IOException e)
acceptJsonFormatVisitorback to summary
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint)

Overrides tools.jackson.databind.ValueSerializer.acceptJsonFormatVisitor.

Implements tools.jackson.databind.jsonFormatVisitors.JsonFormatVisitable.acceptJsonFormatVisitor.

Default implementation specifies no format. This behavior is usually overriden by custom serializers.

Annotations
@Override
acceptJsonFormatVisitorForBinaryback to summary
protected void acceptJsonFormatVisitorForBinary(JsonFormatVisitorWrapper visitor, JavaType typeHint)

Helper method for handling Binary values: typically serialized as Base64-encoded data (in textual formats) or native binary (binary formats).

createSchemaNodeback to summary
protected ObjectNode createSchemaNode(String type)
createSchemaNodeback to summary
protected ObjectNode createSchemaNode(String type, boolean isOptional)
findAnnotatedContentSerializerback to summary
protected ValueSerializer<?> findAnnotatedContentSerializer(SerializationContext serializers, BeanProperty property)

Convenience method for finding out possibly configured content value serializer.

findContextualConvertingSerializerback to summary
protected ValueSerializer<?> findContextualConvertingSerializer(SerializationContext provider, BeanProperty prop, ValueSerializer<?> existingSerializer)

Helper method that can be used to see if specified property has annotation indicating that a converter is to be used for contained values (contents of structured types; array/List/Map values)

Parameters
existingSerializer:ValueSerializer<?>

(optional) configured content serializer if one already exists.

findFormatFeatureback to summary
protected Boolean findFormatFeature(SerializationContext provider, BeanProperty prop, Class<?> typeForDefaults, JsonFormat.Feature feat)

Convenience method that uses findFormatOverrides to find possible defaults and/of overrides, and then calls JsonFormat.Value.getFeature(...) to find whether that feature has been specifically marked as enabled or disabled.

Parameters
typeForDefaults:Class<?>

Type (erased) used for finding default format settings, if any

findFormatOverridesback to summary
protected JsonFormat.Value findFormatOverrides(SerializationContext provider, BeanProperty prop, Class<?> typeForDefaults)

Helper method that may be used to find if this deserializer has specific JsonFormat settings, either via property, or through type-specific defaulting.

Parameters
typeForDefaults:Class<?>

Type (erased) used for finding default format settings, if any

findIncludeOverridesback to summary
protected JsonInclude.Value findIncludeOverrides(SerializationContext provider, BeanProperty prop, Class<?> typeForDefaults)
findPropertyFilterback to summary
protected PropertyFilter findPropertyFilter(SerializationContext provider, Object filterId, Object valueToFilter)

Helper method used to locate filter that is needed, based on filter id this serializer was constructed with.

handledTypeback to summary
public Class<?> handledType()

Overrides tools.jackson.databind.ValueSerializer.handledType.

Doc from tools.jackson.databind.ValueSerializer.handledType.

Method for accessing type of Objects this serializer can handle. Note that this information is not guaranteed to be exact -- it may be a more generic (super-type) -- but it should not be incorrect (return a non-related type).

Note

starting with 3.0, left abstract.

Annotations
@Override
isDefaultSerializerback to summary
protected boolean isDefaultSerializer(ValueSerializer<?> serializer)

Method that can be called to determine if given serializer is the default serializer Jackson uses; as opposed to a custom serializer installed by a module or calling application. Determination is done using JacksonStdImpl annotation on serializer class.

serializeback to summary
public abstract void serialize(T value, JsonGenerator gen, SerializationContext provider) throws JacksonException

Implements abstract tools.jackson.databind.ValueSerializer.serialize.

Doc from tools.jackson.databind.ValueSerializer.serialize.

Method that can be called to ask implementation to serialize values of type this serializer handles.

Annotations
@Override
visitArrayFormatback to summary
protected void visitArrayFormat(JsonFormatVisitorWrapper visitor, JavaType typeHint, ValueSerializer<?> itemSerializer, JavaType itemType)
visitArrayFormatback to summary
protected void visitArrayFormat(JsonFormatVisitorWrapper visitor, JavaType typeHint, JsonFormatTypes itemType)
visitFloatFormatback to summary
protected void visitFloatFormat(JsonFormatVisitorWrapper visitor, JavaType typeHint, JsonParser.NumberType numberType)

Helper method that calls necessary visit method(s) to indicate that the underlying JSON type is a floating-point JSON number.

visitIntFormatback to summary
protected void visitIntFormat(JsonFormatVisitorWrapper visitor, JavaType typeHint, JsonParser.NumberType numberType)

Helper method that calls necessary visit method(s) to indicate that the underlying JSON type is JSON Integer number.

visitIntFormatback to summary
protected void visitIntFormat(JsonFormatVisitorWrapper visitor, JavaType typeHint, JsonParser.NumberType numberType, JsonValueFormat format)

Helper method that calls necessary visit method(s) to indicate that the underlying JSON type is JSON Integer number, but that there is also a further format restriction involved.

visitStringFormatback to summary
protected void visitStringFormat(JsonFormatVisitorWrapper visitor, JavaType typeHint)

Helper method that calls necessary visit method(s) to indicate that the underlying JSON type is JSON String.

visitStringFormatback to summary
protected void visitStringFormat(JsonFormatVisitorWrapper visitor, JavaType typeHint, JsonValueFormat format)

Helper method that calls necessary visit method(s) to indicate that the underlying JSON type is JSON String, but that there is a more refined logical type

wrapAndThrowback to summary
public void wrapAndThrow(SerializationContext ctxt, Throwable t, Object bean, String fieldName) throws JacksonException

Method that will modify caught exception (passed in as argument) as necessary to include reference information, and to ensure it is a subtype of JacksonException, or an unchecked exception.

Rules for wrapping and unwrapping are bit complicated; essentially:

  • Errors are to be passed as is (if uncovered via unwrapping)
  • Wrapped IOExceptions are unpeeled
wrapAndThrowback to summary
public void wrapAndThrow(SerializationContext ctxt, Throwable t, Object bean, int index) throws JacksonException