Top Description Fields Constructors Methods
com.fasterxml.jackson.databind.ser.std

public abstract Class StdSerializer<T>

extends JsonSerializer<T>
implements JsonFormatVisitable, SchemaAware, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, com.fasterxml.jackson.databind.jsonschema.SchemaAware, com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable
Known Direct Subclasses
com.fasterxml.jackson.databind.ser.std.ToEmptyObjectSerializer, com.fasterxml.jackson.databind.ser.std.TokenBufferSerializer, com.fasterxml.jackson.databind.ser.std.ToStringSerializerBase, com.fasterxml.jackson.databind.ext.CoreXMLSerializers.XMLGregorianCalendarSerializer, com.fasterxml.jackson.databind.ext.DOMSerializer, com.fasterxml.jackson.databind.ser.ContainerSerializer, com.fasterxml.jackson.databind.ser.impl.FailingSerializer, com.fasterxml.jackson.databind.ser.impl.UnsupportedTypeSerializer, com.fasterxml.jackson.databind.ser.std.BeanSerializerBase, com.fasterxml.jackson.databind.ser.std.ByteArraySerializer, com.fasterxml.jackson.databind.ser.std.JsonValueSerializer, com.fasterxml.jackson.databind.ser.std.NullSerializer, com.fasterxml.jackson.databind.ser.std.RawSerializer, com.fasterxml.jackson.databind.ser.std.ReferenceTypeSerializer, com.fasterxml.jackson.databind.ser.std.SerializableSerializer, com.fasterxml.jackson.databind.ser.std.StaticListSerializerBase, com.fasterxml.jackson.databind.ser.std.StdArraySerializers.CharArraySerializer, com.fasterxml.jackson.databind.ser.std.StdDelegatingSerializer, com.fasterxml.jackson.databind.ser.std.StdKeySerializer, com.fasterxml.jackson.databind.ser.std.StdKeySerializers.Default, com.fasterxml.jackson.databind.ser.std.StdKeySerializers.Dynamic, com.fasterxml.jackson.databind.ser.std.StdKeySerializers.StringKeySerializer, com.fasterxml.jackson.databind.ser.std.StdKeySerializers.EnumKeySerializer, com.fasterxml.jackson.databind.ser.std.StdScalarSerializer
Annotations
@SuppressWarnings:deprecation
Imports
java.io.IOException, java.lang.reflect.InvocationTargetException, .Type, java.util.Collection, .IdentityHashMap, .Map, com.fasterxml.jackson.annotation.JsonFormat, .JsonInclude, com.fasterxml.jackson.core.*, .JsonParser.NumberType, com.fasterxml.jackson.databind.*, com.fasterxml.jackson.databind.annotation.JacksonStdImpl, com.fasterxml.jackson.databind.introspect.AnnotatedMember, com.fasterxml.jackson.databind.jsonFormatVisitors.*, com.fasterxml.jackson.databind.node.JsonNodeFactory, .ObjectNode, com.fasterxml.jackson.databind.ser.FilterProvider, .PropertyFilter, com.fasterxml.jackson.databind.util.ClassUtil, .Converter

References Deprecated

SchemaAware is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

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<T>
_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.

private static final long

Constructor Summary

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

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

protected
StdSerializer(StdSerializer<?> src)
References Deprecated StdSerializer is deprecated or references (maybe indirectly) at least one deprecated element.

Method Summary

Modifier and TypeMethod and Description
protected static final boolean
protected static final boolean
public void
protected ObjectNode
protected ObjectNode
createSchemaNode(String type, boolean isOptional)

protected JsonSerializer<?>
findAnnotatedContentSerializer(SerializerProvider serializers, BeanProperty property)

Convenience method for finding out possibly configured content value serializer.

protected JsonSerializer<?>
findContextualConvertingSerializer(SerializerProvider provider, BeanProperty property, JsonSerializer<?>
(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 JsonSerializer<?>
findConvertingContentSerializer(SerializerProvider provider, BeanProperty prop, JsonSerializer<?> existingSerializer)
Deprecated Since 2.9 use {link findContextualConvertingSerializer instead

protected Boolean
findFormatFeature(SerializerProvider 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(SerializerProvider 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(SerializerProvider provider, BeanProperty prop, Class<?> typeForDefaults)

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

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

public JsonNode
getSchema(SerializerProvider
The serializer provider.
provider
,
Type
A hint about the type.
typeHint
)

Implements com.fasterxml.jackson.databind.jsonschema.SchemaAware.getSchema.

Deprecated Since 2.15, we recommend use of external JSON Schema generator module

Default implementation simply claims type is "string"; usually overriden by custom serializers.

public JsonNode
getSchema(SerializerProvider
The serializer provider.
provider
,
Type
A hint about the type.
typeHint
,
boolean
Is the type optional
isOptional
)

Implements com.fasterxml.jackson.databind.jsonschema.SchemaAware.getSchema.

Deprecated Since 2.15, we recommend use of external JSON Schema generator module

Default implementation simply claims type is "string"; usually overriden by custom serializers.

public Class<T>
handledType()

Overrides com.fasterxml.jackson.databind.JsonSerializer.handledType.

Method for accessing type of Objects this serializer can handle.

protected boolean
isDefaultSerializer(JsonSerializer<?> 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 to serialize; can not be null.
value
,
JsonGenerator
Generator used to output resulting Json content
gen
,
SerializerProvider
Provider that can be used to get serializers for serializing Objects value contains, if any.
provider
)

Implements abstract com.fasterxml.jackson.databind.JsonSerializer.serialize.

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

protected void
visitArrayFormat(JsonFormatVisitorWrapper visitor, JavaType typeHint, JsonSerializer<?> 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(SerializerProvider provider, 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 IOException, or an unchecked exception.

public void
wrapAndThrow(SerializerProvider provider, Throwable t, Object bean, int index)

Inherited from com.fasterxml.jackson.databind.JsonSerializer:
getDelegateeisEmptyisEmptyisUnwrappingSerializerpropertiesreplaceDelegateeserializeWithTypeunwrappingSerializerusesObjectIdwithFilterIdwithIgnoredProperties

Field Detail

_handledTypeback to summary
protected final Class<T> _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.

Since
2.9
serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

StdSerializerback to summary
protected StdSerializer(Class<T> t)
StdSerializerback to summary
protected StdSerializer(JavaType type)
Annotations
@SuppressWarnings:unchecked
StdSerializerback to summary
protected StdSerializer(Class<?> t, boolean dummy)

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

Annotations
@SuppressWarnings:unchecked
StdSerializerback to summary
protected StdSerializer(StdSerializer<?> src)

References Deprecated

StdSerializer is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Annotations
@SuppressWarnings:unchecked
Since
2.6

Method Detail

_neitherNullback to summary
protected static final boolean _neitherNull(Object a, Object b)
Since
2.9
_nonEmptyback to summary
protected static final boolean _nonEmpty(Collection<?> c)
Since
2.9
acceptJsonFormatVisitorback to summary
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws JsonMappingException

Overrides com.fasterxml.jackson.databind.JsonSerializer.acceptJsonFormatVisitor.

Implements com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable.acceptJsonFormatVisitor.

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

Parameters
typeHint:JavaType

Doc from com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable.acceptJsonFormatVisitor.

Type of element (entity like property) being visited

Annotations
@Override
createSchemaNodeback to summary
protected ObjectNode createSchemaNode(String type)
createSchemaNodeback to summary
protected ObjectNode createSchemaNode(String type, boolean isOptional)
findAnnotatedContentSerializerback to summary
protected JsonSerializer<?> findAnnotatedContentSerializer(SerializerProvider serializers, BeanProperty property) throws JsonMappingException

Convenience method for finding out possibly configured content value serializer.

Since
2.7.4
findContextualConvertingSerializerback to summary
protected JsonSerializer<?> findContextualConvertingSerializer(SerializerProvider provider, BeanProperty property, JsonSerializer<?> existingSerializer) throws JsonMappingException

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:JsonSerializer<?>

(optional) configured content serializer if one already exists.

Since
2.9
findConvertingContentSerializerback to summary
protected JsonSerializer<?> findConvertingContentSerializer(SerializerProvider provider, BeanProperty prop, JsonSerializer<?> existingSerializer) throws JsonMappingException

Deprecated

Since 2.9 use {link findContextualConvertingSerializer instead

Annotations
@Deprecated
findFormatFeatureback to summary
protected Boolean findFormatFeature(SerializerProvider 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

Since
2.7
findFormatOverridesback to summary
protected JsonFormat.Value findFormatOverrides(SerializerProvider 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

Since
2.7
findIncludeOverridesback to summary
protected JsonInclude.Value findIncludeOverrides(SerializerProvider provider, BeanProperty prop, Class<?> typeForDefaults)
Since
2.8
findPropertyFilterback to summary
protected PropertyFilter findPropertyFilter(SerializerProvider provider, Object filterId, Object valueToFilter) throws JsonMappingException

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

Since
2.3
getSchemaback to summary
public JsonNode getSchema(SerializerProvider provider, Type typeHint) throws JsonMappingException

Implements com.fasterxml.jackson.databind.jsonschema.SchemaAware.getSchema.

Deprecated

Since 2.15, we recommend use of external JSON Schema generator module

Default implementation simply claims type is "string"; usually overriden by custom serializers.

Parameters
provider:SerializerProvider

Doc from com.fasterxml.jackson.databind.jsonschema.SchemaAware.getSchema.

The serializer provider.

typeHint:Type

Doc from com.fasterxml.jackson.databind.jsonschema.SchemaAware.getSchema.

A hint about the type.

Returns:JsonNode

Doc from com.fasterxml.jackson.databind.jsonschema.SchemaAware.getSchema.

Json-schema for this serializer.

Annotations
@Deprecated
@Override
getSchemaback to summary
public JsonNode getSchema(SerializerProvider provider, Type typeHint, boolean isOptional) throws JsonMappingException

Implements com.fasterxml.jackson.databind.jsonschema.SchemaAware.getSchema.

Deprecated

Since 2.15, we recommend use of external JSON Schema generator module

Default implementation simply claims type is "string"; usually overriden by custom serializers.

Parameters
provider:SerializerProvider

Doc from com.fasterxml.jackson.databind.jsonschema.SchemaAware.getSchema.

The serializer provider.

typeHint:Type

Doc from com.fasterxml.jackson.databind.jsonschema.SchemaAware.getSchema.

A hint about the type.

isOptional:boolean

Doc from com.fasterxml.jackson.databind.jsonschema.SchemaAware.getSchema.

Is the type optional

Returns:JsonNode

Doc from com.fasterxml.jackson.databind.jsonschema.SchemaAware.getSchema.

Json-schema for this serializer.

Annotations
@Deprecated
@Override
handledTypeback to summary
public Class<T> handledType()

Overrides com.fasterxml.jackson.databind.JsonSerializer.handledType.

Doc from com.fasterxml.jackson.databind.JsonSerializer.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).

Default implementation will return null, which essentially means same as returning Object.class would; that is, that nothing is known about handled type.

Annotations
@Override
isDefaultSerializerback to summary
protected boolean isDefaultSerializer(JsonSerializer<?> 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, SerializerProvider provider) throws IOException

Implements abstract com.fasterxml.jackson.databind.JsonSerializer.serialize.

Doc from com.fasterxml.jackson.databind.JsonSerializer.serialize.

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

Parameters
value:T

Value to serialize; can not be null.

gen:JsonGenerator

Generator used to output resulting Json content

provider:SerializerProvider

Provider that can be used to get serializers for serializing Objects value contains, if any.

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

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

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

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

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

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.

Since
2.7
visitStringFormatback to summary
protected void visitStringFormat(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws JsonMappingException

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

Since
2.7
visitStringFormatback to summary
protected void visitStringFormat(JsonFormatVisitorWrapper visitor, JavaType typeHint, JsonValueFormat format) throws JsonMappingException

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

Since
2.7
wrapAndThrowback to summary
public void wrapAndThrow(SerializerProvider provider, Throwable t, Object bean, String fieldName) throws IOException

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

Rules for wrapping and unwrapping are bit complicated; essentially:

  • Errors are to be passed as is (if uncovered via unwrapping)
  • "Plain" IOExceptions (ones that are not of type JsonMappingException are to be passed as is
wrapAndThrowback to summary
public void wrapAndThrow(SerializerProvider provider, Throwable t, Object bean, int index) throws IOException