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

public abstract Class SerializerProvider

extends DatabindContext
Class Inheritance
Known Direct Subclasses
com.fasterxml.jackson.databind.ser.DefaultSerializerProvider
Imports
java.io.IOException, java.text.DateFormat, java.util.Date, .Locale, .TimeZone, com.fasterxml.jackson.annotation.JsonFormat, .JsonInclude, .ObjectIdGenerator, com.fasterxml.jackson.core.JsonGenerator, .ObjectCodec, com.fasterxml.jackson.databind.cfg.ContextAttributes, .DatatypeFeature, .DatatypeFeatures, com.fasterxml.jackson.databind.deser.ContextualDeserializer, com.fasterxml.jackson.databind.exc.InvalidDefinitionException, .InvalidTypeIdException, com.fasterxml.jackson.databind.introspect.Annotated, .BeanPropertyDefinition, com.fasterxml.jackson.databind.jsontype.TypeSerializer, com.fasterxml.jackson.databind.ser.*, com.fasterxml.jackson.databind.ser.impl.FailingSerializer, .ReadOnlyClassToSerializerMap, .TypeWrappedSerializer, .UnknownSerializer, .WritableObjectId, com.fasterxml.jackson.databind.ser.std.NullSerializer, com.fasterxml.jackson.databind.type.TypeFactory, com.fasterxml.jackson.databind.util.ClassUtil, .TokenBuffer

Class that defines API used by ObjectMapper and JsonSerializers to obtain serializers capable of serializing instances of specific types; as well as the default implementation of the functionality.

Provider handles caching aspects of serializer handling; all construction details are delegated to SerializerFactory instance.

Object life-cycle is such that an initial instance ("blueprint") is created and referenced by ObjectMapper and ObjectWriter instances; but for actual usage, a configured instance is created by using a create method in sub-class com.fasterxml.jackson.databind.ser.DefaultSerializerProvider. Only this instance can be used for actual serialization calls; blueprint object is only to be used for creating instances.

Field Summary

Modifier and TypeField and Description
protected transient ContextAttributes
_attributes

Lazily-constructed holder for per-call attributes.

protected final SerializationConfig
_config

Serialization configuration to use for serialization processing.

protected DateFormat
_dateFormat

Lazily acquired and instantiated formatter object: initialized first time it is needed, reused afterwards.

protected JsonSerializer<Object>
_keySerializer

Serializer used to output non-null keys of Maps (which will get output as JSON Objects), if not null; if null, us the standard default key serializer.

protected final ReadOnlyClassToSerializerMap
_knownSerializers

For fast lookups, we will have a local non-shared read-only map that contains serializers previously fetched.

protected JsonSerializer<Object>
_nullKeySerializer

Serializer used to (try to) output a null key, due to an entry of java.util.Map having null key.

protected JsonSerializer<Object>
_nullValueSerializer

Serializer used to output a null value.

protected final Class<?>
_serializationView

View used for currently active serialization, if any.

protected final SerializerCache
_serializerCache

Cache for doing type-to-value-serializer lookups.

protected final SerializerFactory
_serializerFactory

Factory used for constructing actual serializer instances.

protected final boolean
_stdNullValueSerializer

Flag set to indicate that we are using vanilla null value serialization

protected JsonSerializer<Object>
_unknownTypeSerializer

Serializer that gets called for values of types for which no serializers can be constructed.

protected static final boolean
CACHE_UNKNOWN_MAPPINGS

Setting for determining whether mappings for "unknown classes" should be cached for faster resolution.

public static final JsonSerializer<Object>
protected static final JsonSerializer<Object>
DEFAULT_UNKNOWN_SERIALIZER

Placeholder serializer used when java.lang.Object typed property is marked to be serialized.

Constructor Summary

AccessConstructor and Description
public
SerializerProvider()

Constructor for creating master (or "blue-print") provider object, which is only used as the template for constructing per-binding instances.

protected
SerializerProvider(SerializerProvider
Blueprint object used as the baseline for this instance
src
,
SerializationConfig config, SerializerFactory f)

"Copy-constructor", used by sub-classes when creating actual non-blueprint instances to use.

protected
SerializerProvider(SerializerProvider src)

Copy-constructor used when making a copy of a blueprint instance.

protected

Method Summary

Modifier and TypeMethod and Description
protected JsonSerializer<Object>
_createAndCacheUntypedSerializer(Class<?> rawType)

Method that will try to construct a value serializer; and if one is successfully created, cache it for reuse.

protected JsonSerializer<Object>
protected JsonSerializer<Object>
protected final DateFormat
protected JsonSerializer<Object>

Returns:

Serializer if one can be found, null if not.
_findExplicitUntypedSerializer
(Class<?> runtimeType)

Method that will try to find a serializer, either from cache or by constructing one; but will not return an "unknown" serializer if this cannot be done but rather returns null.

protected JsonSerializer<Object>
_handleContextualResolvable(JsonSerializer<?> ser, BeanProperty property)

Helper method called to resolve and contextualize given serializer, if and as necessary.

protected JsonSerializer<Object>
protected void
public TokenBuffer
bufferForValueConversion(ObjectCodec oc)

Specialized factory method used when we are converting values and do not typically have or use "real" parsers or generators.

public final TokenBuffer
bufferForValueConversion()

Specialized factory method used when we are converting values and do not typically have or use "real" parsers or generators.

public final boolean
canOverrideAccessModifiers()

Implements abstract com.fasterxml.jackson.databind.DatabindContext.canOverrideAccessModifiers.

Convenience method for accessing serialization view in use (if any); equivalent to:
   getConfig().canOverrideAccessModifiers();
public JavaType
constructSpecializedType(JavaType baseType, Class<?> subclass)

Implements abstract com.fasterxml.jackson.databind.DatabindContext.constructSpecializedType.

Convenience method for constructing subtypes, retaining generic type parameter (if any).
public void
defaultSerializeDateKey(long timestamp, JsonGenerator gen)

Method that will handle serialization of Dates used as java.util.Map keys, based on SerializationFeature#WRITE_DATE_KEYS_AS_TIMESTAMPS value (and if using textual representation, configured date format)

public void
defaultSerializeDateKey(Date date, JsonGenerator gen)

Method that will handle serialization of Dates used as java.util.Map keys, based on SerializationFeature#WRITE_DATE_KEYS_AS_TIMESTAMPS value (and if using textual representation, configured date format)

public final void
defaultSerializeDateValue(long timestamp, JsonGenerator gen)

Method that will handle serialization of Date(-like) values, using SerializationConfig settings to determine expected serialization behavior.

public final void
defaultSerializeDateValue(Date date, JsonGenerator gen)

Method that will handle serialization of Date(-like) values, using SerializationConfig settings to determine expected serialization behavior.

public final void
defaultSerializeField(String fieldName, Object value, JsonGenerator gen)

Convenience method that will serialize given field with specified value.

public final void
public final void
defaultSerializeValue(Object value, JsonGenerator gen)

Convenience method that will serialize given value (which can be null) using standard serializer locating functionality.

public JsonSerializer<Object>
findContentValueSerializer(JavaType
Type of values to serialize
valueType
,
BeanProperty
Property that indirectly refers to value being serialized (optional, may be null for root level serializers)
property
)

Alternative to findPrimaryPropertySerializer(JavaType, BeanProperty) called not for primary value, but "content" of such primary serializer: element of an array or java.util.Collection, value of java.util.Map entry and so on.

public JsonSerializer<Object>
public JsonSerializer<Object>
findKeySerializer(JavaType keyType, BeanProperty property)

Method called to get the serializer to use for serializing non-null Map keys.

public JsonSerializer<Object>
findKeySerializer(Class<?> rawKeyType, BeanProperty property)

public JsonSerializer<Object>

Returns:

JsonSerializer that handles the serialization of null keys, usually by throwing an exception or using an empty String, but other behaviors are also possible.
findNullKeySerializer
(JavaType serializationType, BeanProperty property)

Method called to find a serializer to serializes Map keys that are nulls, as JSON does not allow any non-String value as a key, including null.

public JsonSerializer<Object>
findNullValueSerializer(BeanProperty property)

Method called to get the serializer to use for serializing null values for specified property.

public abstract WritableObjectId
findObjectId(Object forPojo, ObjectIdGenerator<?> generatorType)

Method called to find the Object Id for given POJO, if one has been generated.

public JsonSerializer<Object>
findPrimaryPropertySerializer(JavaType
Type of values to serialize
valueType
,
BeanProperty
Property that is being handled; will never be null, and its type has to match valueType parameter.
property
)

Similar to findValueSerializer(JavaType, BeanProperty), but used when finding "primary" property value serializer (one directly handling value of the property).

public JsonSerializer<Object>
public JsonSerializer<Object>
findTypedValueSerializer(Class<?>
Type for purpose of locating a serializer; usually dynamic runtime type, but can also be static declared type, depending on configuration
valueType
,
boolean
Whether resulting value serializer should be cached or not; this is just a hint
cache
,
BeanProperty
When creating secondary serializers, property for which serializer is needed: annotations of the property (or bean that contains it) may be checked to create contextual serializers.
property
)

Method called to locate regular serializer, matching type serializer, and if both found, wrap them in a serializer that calls both in correct sequence.

public JsonSerializer<Object>
findTypedValueSerializer(JavaType
Declared type of value being serialized (which may not be actual runtime type); used for finding both value serializer and type serializer to use for adding polymorphic type (if any)
valueType
,
boolean
Whether resulting value serializer should be cached or not; this is just a hint
cache
,
BeanProperty
When creating secondary serializers, property for which serializer is needed: annotations of the property (or bean that contains it) may be checked to create contextual serializers.
property
)

Method called to locate regular serializer, matching type serializer, and if both found, wrap them in a serializer that calls both in correct sequence.

public TypeSerializer
findTypeSerializer(JavaType javaType)

Method called to get the TypeSerializer to use for including Type Id necessary for serializing for the given Java class.

public JsonSerializer<Object>
findValueSerializer(Class<?> valueType, BeanProperty property)

Method called to get hold of a serializer for a value of given type; or if no such serializer can be found, a default handler (which may do a best-effort generic serialization or just simply throw an exception when invoked).

public JsonSerializer<Object>
findValueSerializer(JavaType valueType, BeanProperty
When creating secondary serializers, property for which serializer is needed: annotations of the property (or bean that contains it) may be checked to create contextual serializers.
property
)

Similar to findValueSerializer(Class, BeanProperty), but takes full generics-aware type instead of raw class.

public JsonSerializer<Object>
findValueSerializer(Class<?> valueType)

Method variant used when we do NOT want contextualization to happen; it will need to be handled at a later point, but caller wants to be able to do that as needed; sometimes to avoid infinite loops

public JsonSerializer<Object>
findValueSerializer(JavaType valueType)

Method variant used when we do NOT want contextualization to happen; it will need to be handled at a later point, but caller wants to be able to do that as needed; sometimes to avoid infinite loops

public final Class<?>
getActiveView()

Implements abstract com.fasterxml.jackson.databind.DatabindContext.getActiveView.

Accessor for locating currently active view, if any; returns null if no view has been set.
public final AnnotationIntrospector
getAnnotationIntrospector()

Implements abstract com.fasterxml.jackson.databind.DatabindContext.getAnnotationIntrospector.

Convenience method for accessing serialization view in use (if any); equivalent to:
   getConfig().getAnnotationIntrospector();
public Object
getAttribute(Object
Key of the attribute to get
key
)

Implements abstract com.fasterxml.jackson.databind.DatabindContext.getAttribute.

Method for accessing attributes available in this context.
public final SerializationConfig
getConfig()

Implements abstract com.fasterxml.jackson.databind.DatabindContext.getConfig.

Method for accessing configuration for the serialization processing.
public final DatatypeFeatures
public JsonSerializer<Object>
public JsonSerializer<Object>
public final JsonFormat.Value
public final JsonInclude.Value
public final FilterProvider
getFilterProvider()

Convenience method for accessing provider to find serialization filters used, equivalent to calling:

   getConfig().getFilterProvider();
public JsonGenerator
getGenerator()

Note

current implementation simply returns `null` as generator is not yet assigned to this provider.

public Locale
getLocale()

Implements abstract com.fasterxml.jackson.databind.DatabindContext.getLocale.

Method for accessing default Locale to use: convenience method for
   getConfig().getLocale();
public TimeZone
getTimeZone()

Implements abstract com.fasterxml.jackson.databind.DatabindContext.getTimeZone.

Method for accessing default TimeZone to use: convenience method for
   getConfig().getTimeZone();
public final TypeFactory
public JsonSerializer<Object>
getUnknownTypeSerializer(Class<?>
Type for which no serializer is found
unknownType
)

Method called to get the serializer to use if provider cannot determine an actual type-specific serializer to use; typically when none of SerializerFactory instances are able to construct a serializer.

public JsonSerializer<?>
handlePrimaryContextualization(JsonSerializer<?> ser, BeanProperty
Property for which the given primary serializer is used; never null.
property
)

Method called for primary property serializers (ones directly created to serialize values of a POJO property), to handle details of resolving ContextualSerializer with given property context.

public JsonSerializer<?>
handleSecondaryContextualization(JsonSerializer<?> ser, BeanProperty
Property for which serializer is used, if any; null when deserializing root values
property
)

Method called for secondary property serializers (ones NOT directly created to serialize values of a POJO property but instead created as a dependant serializer -- such as value serializers for structured types, or serializers for root values) to handle details of resolving ContextualDeserializer with given property context.

public final boolean
hasSerializationFeatures(int featureMask)

"Bulk" access method for checking that all features specified by mask are enabled.

public abstract Object
includeFilterInstance(BeanPropertyDefinition
(optional) If filter is created for a property, that property; `null` if filter created via defaulting, global or per-type.
forProperty
,
Class<?> filterClass)

Method that can be called to construct and configure JsonInclude filter instance, given a Class to instantiate (with default constructor, by default).

public abstract boolean
includeFilterSuppressNulls(Object filter)

Follow-up method that may be called after calling includeFilterInstance, to check handling of `null` values by the filter.

public JsonMappingException
invalidTypeIdException(JavaType baseType, String typeId, String extraDesc)

Implements abstract com.fasterxml.jackson.databind.DatabindContext.invalidTypeIdException.

Helper method for constructing exception to indicate that given type id could not be resolved to a valid subtype of specified base type.
public final boolean
isEnabled(MapperFeature feature)

Implements abstract com.fasterxml.jackson.databind.DatabindContext.isEnabled.

Convenience method for checking whether specified Mapper feature is enabled or not.
public final boolean
isEnabled(DatatypeFeature feature)

Implements abstract com.fasterxml.jackson.databind.DatabindContext.isEnabled.

Method for checking whether specified datatype feature is enabled or not.
public final boolean
isEnabled(SerializationFeature feature)

Convenience method for checking whether specified serialization feature is enabled or not.

public boolean
isUnknownTypeSerializer(JsonSerializer<?> ser)

Helper method called to see if given serializer is considered to be something returned by getUnknownTypeSerializer, that is, something for which no regular serializer was found or constructed.

public JsonMappingException
mappingException(String message, Object... msgArgs)

Deprecated Since 2.9
Factory method for constructing a JsonMappingException; usually only indirectly used by calling reportMappingProblem(String, Object...).
protected JsonMappingException
mappingException(Throwable t, String message, Object... msgArgs)

Deprecated Since 2.9
Factory method for constructing a JsonMappingException; usually only indirectly used by calling reportMappingProblem(Throwable, String, Object...)
public <T> T
reportBadDefinition(JavaType type, String msg)

Implements abstract com.fasterxml.jackson.databind.DatabindContext.reportBadDefinition.

Helper method called to indicate a generic problem that stems from type definition(s), not input data, or input/output state; typically this means throwing a com.fasterxml.jackson.databind.exc.InvalidDefinitionException.
public <T> T
public <T> T
public <T> T
reportBadPropertyDefinition(BeanDescription bean, BeanPropertyDefinition prop, String message, Object... msgArgs)

Helper method called to indicate problem in POJO (serialization) definitions or settings regarding specific property (of a type), unrelated to actual JSON content to map.

public <T> T
reportBadTypeDefinition(BeanDescription bean, String msg, Object... msgArgs)

Helper method called to indicate problem in POJO (serialization) definitions or settings regarding specific Java type, unrelated to actual JSON content to map.

public void
reportMappingProblem(String message, Object... args)

Helper method called to indicate problem; default behavior is to construct and throw a JsonMappingException, but in future may collect more than one and only throw after certain number, or at the end of serialization.

public void
reportMappingProblem(Throwable t, String message, Object... msgArgs)

Helper method called to indicate problem; default behavior is to construct and throw a JsonMappingException, but in future may collect more than one and only throw after certain number, or at the end of serialization.

public abstract JsonSerializer<Object>
serializerInstance(Annotated
Annotated entity that contained definition
annotated
,
Object
Serializer definition: either an instance or class
serDef
)

Method that can be called to construct and configure serializer instance, either given a Class to instantiate (with default constructor), or an uninitialized serializer instance.

public SerializerProvider
setAttribute(Object
Key of the attribute to set
key
,
Object
Value to set attribute to
value
)

Implements abstract com.fasterxml.jackson.databind.DatabindContext.setAttribute.

Method for setting per-call value of given attribute.
public void
setDefaultKeySerializer(JsonSerializer<Object> ks)

Method that can be used to specify serializer to use for serializing all non-null JSON property names, unless more specific key serializer is found (i.e. if not custom key serializer has been registered for Java type).

public void
setNullKeySerializer(JsonSerializer<Object> nks)

Method that can be used to specify serializer that will be used to write JSON property names matching null keys for Java Maps (which will otherwise throw an exception if try write such property name)

public void
setNullValueSerializer(JsonSerializer<Object> nvs)

Method that can be used to specify serializer that will be used to write JSON values matching Java null values instead of default one (which simply writes JSON null).

Inherited from com.fasterxml.jackson.databind.DatabindContext:
_colonConcat_desc_format_quotedString_throwNotASubtype_throwSubtypeClassNotAllowed_throwSubtypeNameNotAllowed_truncateconstructTypeconverterInstanceobjectIdGeneratorInstanceobjectIdResolverInstancereportBadDefinitionresolveAndValidateSubTyperesolveSubType