Class DefaultSerializerProvider
- java.lang.Object
-
- com.fasterxml.jackson.databind.DatabindContext
-
- com.fasterxml.jackson.databind.SerializerProvider
-
- com.fasterxml.jackson.databind.ser.DefaultSerializerProvider
-
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
DefaultSerializerProvider.Impl
public abstract class DefaultSerializerProvider extends SerializerProvider implements Serializable
Standard implementation used byObjectMapper: adds methods only exposed toObjectMapper, as well as constructors.Note that class is abstract just because it does not define
createInstance(com.fasterxml.jackson.databind.SerializationConfig, com.fasterxml.jackson.databind.ser.SerializerFactory)method.Also note that all custom
SerializerProviderimplementations must sub-class this class:ObjectMapperrequires this type, not basic provider type.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDefaultSerializerProvider.ImplConcrete implementation that defines factory method(s), defined as final.
-
Field Summary
Fields Modifier and Type Field Description protected com.fasterxml.jackson.core.JsonGenerator_generatorGenerator used for serialization.protected ArrayList<com.fasterxml.jackson.annotation.ObjectIdGenerator<?>>_objectIdGeneratorsprotected Map<Object,WritableObjectId>_seenObjectIdsPer-serialization map Object Ids that have seen so far, iff Object Id handling is enabled.-
Fields inherited from class com.fasterxml.jackson.databind.SerializerProvider
_attributes, _config, _dateFormat, _keySerializer, _knownSerializers, _nullKeySerializer, _nullValueSerializer, _serializationView, _serializerCache, _serializerFactory, _stdNullValueSerializer, _unknownTypeSerializer, CACHE_UNKNOWN_MAPPINGS, DEFAULT_NULL_KEY_SERIALIZER, DEFAULT_UNKNOWN_SERIALIZER
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedDefaultSerializerProvider()protectedDefaultSerializerProvider(DefaultSerializerProvider src)protectedDefaultSerializerProvider(SerializerProvider src, SerializationConfig config, SerializerFactory f)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected Map<Object,WritableObjectId>_createObjectIdMap()Overridable helper method used for creatingMapused for storing mappings from serializable objects to their Object Ids.protected void_serializeNull(com.fasterxml.jackson.core.JsonGenerator gen)Helper method called when root value to serialize is nullvoidacceptJsonFormatVisitor(JavaType javaType, JsonFormatVisitorWrapper visitor)The method to be called byObjectMapperandObjectWriterto to expose the format of the given to to the given visitorintcachedSerializersCount()Method that can be used to determine how many serializers this provider is caching currently (if it does caching: default implementation does) Exact count depends on what kind of serializers get cached; default implementation caches all serializers, including ones that are eagerly constructed (for optimal access speed)DefaultSerializerProvidercopy()Method needed to ensure thatObjectMapper.copy()will work properly; specifically, that caches are cleared, but settings will otherwise remain identical; and that no sharing of state occurs.abstract DefaultSerializerProvidercreateInstance(SerializationConfig config, SerializerFactory jsf)Method that sub-classes need to implement: used to create a non-blueprint instances from the blueprint.WritableObjectIdfindObjectId(Object forPojo, com.fasterxml.jackson.annotation.ObjectIdGenerator<?> generatorType)Method called to find the Object Id for given POJO, if one has been generated.voidflushCachedSerializers()Method that will drop all serializers currently cached by this provider.JsonSchemagenerateJsonSchema(Class<?> type)Deprecated.Should not be used any morecom.fasterxml.jackson.core.JsonGeneratorgetGenerator()Accessor for theJsonGeneratorcurrently in use for serializing content.booleanhasSerializerFor(Class<?> cls, AtomicReference<Throwable> cause)Method that can be called to see if this serializer provider can find a serializer for an instance of given class.ObjectincludeFilterInstance(BeanPropertyDefinition forProperty, Class<?> filterClass)Method that can be called to construct and configureJsonIncludefilter instance, given aClassto instantiate (with default constructor, by default).booleanincludeFilterSuppressNulls(Object filter)Follow-up method that may be called after callingSerializerProvider.includeFilterInstance(com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition, java.lang.Class<?>), to check handling of `null` values by the filter.voidserializePolymorphic(com.fasterxml.jackson.core.JsonGenerator gen, Object value, JavaType rootType, JsonSerializer<Object> valueSer, TypeSerializer typeSer)Alternate serialization call used for polymorphic types, whenTypeSerializeris already known, but the actual serializer may or may not be.JsonSerializer<Object>serializerInstance(Annotated annotated, Object serDef)Method that can be called to construct and configure serializer instance, either given aClassto instantiate (with default constructor), or an uninitialized serializer instance.voidserializeValue(com.fasterxml.jackson.core.JsonGenerator gen, Object value)The method to be called byObjectMapperandObjectWriterfor serializing given value, using serializers that this provider has access to (via caching and/or creating new serializers as need be).voidserializeValue(com.fasterxml.jackson.core.JsonGenerator gen, Object value, JavaType rootType)The method to be called byObjectMapperandObjectWriterfor serializing given value (assumed to be of specified root type, instead of runtime type of value), using serializers that this provider has access to (via caching and/or creating new serializers as need be),voidserializeValue(com.fasterxml.jackson.core.JsonGenerator gen, Object value, JavaType rootType, JsonSerializer<Object> ser)The method to be called byObjectWriterfor serializing given value (assumed to be of specified root type, instead of runtime type of value), when it may know specificJsonSerializerto use.-
Methods inherited from class com.fasterxml.jackson.databind.SerializerProvider
_createAndCacheUntypedSerializer, _createAndCacheUntypedSerializer, _createUntypedSerializer, _dateFormat, _findExplicitUntypedSerializer, _handleContextualResolvable, _handleResolvable, _reportIncompatibleRootType, canOverrideAccessModifiers, defaultSerializeDateKey, defaultSerializeDateKey, defaultSerializeDateValue, defaultSerializeDateValue, defaultSerializeField, defaultSerializeNull, defaultSerializeValue, findKeySerializer, findKeySerializer, findNullKeySerializer, findNullValueSerializer, findPrimaryPropertySerializer, findPrimaryPropertySerializer, findTypedValueSerializer, findTypedValueSerializer, findTypeSerializer, findValueSerializer, findValueSerializer, findValueSerializer, findValueSerializer, getActiveView, getAnnotationIntrospector, getAttribute, getConfig, getDefaultNullKeySerializer, getDefaultNullValueSerializer, getDefaultPropertyFormat, getDefaultPropertyInclusion, getFilterProvider, getLocale, getSerializationView, getTimeZone, getTypeFactory, getUnknownTypeSerializer, handlePrimaryContextualization, handleSecondaryContextualization, hasSerializationFeatures, invalidTypeIdException, isEnabled, isEnabled, isUnknownTypeSerializer, mappingException, mappingException, reportBadDefinition, reportBadDefinition, reportBadDefinition, reportBadPropertyDefinition, reportBadTypeDefinition, reportMappingProblem, reportMappingProblem, setAttribute, setDefaultKeySerializer, setNullKeySerializer, setNullValueSerializer
-
Methods inherited from class com.fasterxml.jackson.databind.DatabindContext
_colonConcat, _desc, _format, _quotedString, _throwNotASubtype, _throwSubtypeClassNotAllowed, _throwSubtypeNameNotAllowed, _truncate, constructSpecializedType, constructType, converterInstance, objectIdGeneratorInstance, objectIdResolverInstance, reportBadDefinition, resolveAndValidateSubType, resolveSubType
-
-
-
-
Field Detail
-
_seenObjectIds
protected transient Map<Object,WritableObjectId> _seenObjectIds
Per-serialization map Object Ids that have seen so far, iff Object Id handling is enabled.
-
_objectIdGenerators
protected transient ArrayList<com.fasterxml.jackson.annotation.ObjectIdGenerator<?>> _objectIdGenerators
-
_generator
protected transient com.fasterxml.jackson.core.JsonGenerator _generator
Generator used for serialization. Needed mostly for error reporting purposes.- Since:
- 2.8
-
-
Constructor Detail
-
DefaultSerializerProvider
protected DefaultSerializerProvider()
-
DefaultSerializerProvider
protected DefaultSerializerProvider(SerializerProvider src, SerializationConfig config, SerializerFactory f)
-
DefaultSerializerProvider
protected DefaultSerializerProvider(DefaultSerializerProvider src)
-
-
Method Detail
-
createInstance
public abstract DefaultSerializerProvider createInstance(SerializationConfig config, SerializerFactory jsf)
Method that sub-classes need to implement: used to create a non-blueprint instances from the blueprint. This is needed to retain state during serialization.
-
copy
public DefaultSerializerProvider copy()
Method needed to ensure thatObjectMapper.copy()will work properly; specifically, that caches are cleared, but settings will otherwise remain identical; and that no sharing of state occurs.- Since:
- 2.5
-
serializerInstance
public JsonSerializer<Object> serializerInstance(Annotated annotated, Object serDef) throws JsonMappingException
Description copied from class:SerializerProviderMethod that can be called to construct and configure serializer instance, either given aClassto instantiate (with default constructor), or an uninitialized serializer instance. Either way, serialize will be properly resolved (viaResolvableSerializer) and/or contextualized (viaContextualSerializer) as necessary.- Specified by:
serializerInstancein classSerializerProvider- Parameters:
annotated- Annotated entity that contained definitionserDef- Serializer definition: either an instance or class- Throws:
JsonMappingException
-
includeFilterInstance
public Object includeFilterInstance(BeanPropertyDefinition forProperty, Class<?> filterClass)
Description copied from class:SerializerProviderMethod that can be called to construct and configureJsonIncludefilter instance, given aClassto instantiate (with default constructor, by default).- Specified by:
includeFilterInstancein classSerializerProvider- Parameters:
forProperty- (optional) If filter is created for a property, that property; `null` if filter created via defaulting, global or per-type.
-
includeFilterSuppressNulls
public boolean includeFilterSuppressNulls(Object filter) throws JsonMappingException
Description copied from class:SerializerProviderFollow-up method that may be called after callingSerializerProvider.includeFilterInstance(com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition, java.lang.Class<?>), to check handling of `null` values by the filter.- Specified by:
includeFilterSuppressNullsin classSerializerProvider- Throws:
JsonMappingException
-
findObjectId
public WritableObjectId findObjectId(Object forPojo, com.fasterxml.jackson.annotation.ObjectIdGenerator<?> generatorType)
Description copied from class:SerializerProviderMethod called to find the Object Id for given POJO, if one has been generated. Will always return a non-null Object; contents vary depending on whether an Object Id already exists or not.- Specified by:
findObjectIdin classSerializerProvider
-
_createObjectIdMap
protected Map<Object,WritableObjectId> _createObjectIdMap()
Overridable helper method used for creatingMapused for storing mappings from serializable objects to their Object Ids.- Since:
- 2.3
-
hasSerializerFor
public boolean hasSerializerFor(Class<?> cls, AtomicReference<Throwable> cause)
Method that can be called to see if this serializer provider can find a serializer for an instance of given class.Note that no Exceptions are thrown, including unchecked ones: implementations are to swallow exceptions if necessary.
-
getGenerator
public com.fasterxml.jackson.core.JsonGenerator getGenerator()
Accessor for theJsonGeneratorcurrently in use for serializing content. Null for blueprint instances; non-null for actual active provider instances.- Overrides:
getGeneratorin classSerializerProvider- Since:
- 2.8
-
serializeValue
public void serializeValue(com.fasterxml.jackson.core.JsonGenerator gen, Object value) throws IOExceptionThe method to be called byObjectMapperandObjectWriterfor serializing given value, using serializers that this provider has access to (via caching and/or creating new serializers as need be).- Throws:
IOException
-
serializeValue
public void serializeValue(com.fasterxml.jackson.core.JsonGenerator gen, Object value, JavaType rootType) throws IOExceptionThe method to be called byObjectMapperandObjectWriterfor serializing given value (assumed to be of specified root type, instead of runtime type of value), using serializers that this provider has access to (via caching and/or creating new serializers as need be),- Parameters:
rootType- Type to use for locating serializer to use, instead of actual runtime type. Must be actual type, or one of its super types- Throws:
IOException
-
serializeValue
public void serializeValue(com.fasterxml.jackson.core.JsonGenerator gen, Object value, JavaType rootType, JsonSerializer<Object> ser) throws IOExceptionThe method to be called byObjectWriterfor serializing given value (assumed to be of specified root type, instead of runtime type of value), when it may know specificJsonSerializerto use.- Parameters:
rootType- Type to use for locating serializer to use, instead of actual runtime type, if no serializer is passedser- Root Serializer to use, if not null- Throws:
IOException- Since:
- 2.1
-
serializePolymorphic
public void serializePolymorphic(com.fasterxml.jackson.core.JsonGenerator gen, Object value, JavaType rootType, JsonSerializer<Object> valueSer, TypeSerializer typeSer) throws IOExceptionAlternate serialization call used for polymorphic types, whenTypeSerializeris already known, but the actual serializer may or may not be.- Throws:
IOException- Since:
- 2.6
-
_serializeNull
protected void _serializeNull(com.fasterxml.jackson.core.JsonGenerator gen) throws IOExceptionHelper method called when root value to serialize is null- Throws:
IOException- Since:
- 2.3
-
cachedSerializersCount
public int cachedSerializersCount()
Method that can be used to determine how many serializers this provider is caching currently (if it does caching: default implementation does) Exact count depends on what kind of serializers get cached; default implementation caches all serializers, including ones that are eagerly constructed (for optimal access speed)The main use case for this method is to allow conditional flushing of serializer cache, if certain number of entries is reached.
-
flushCachedSerializers
public void flushCachedSerializers()
Method that will drop all serializers currently cached by this provider. This can be used to remove memory usage (in case some serializers are only used once or so), or to force re-construction of serializers after configuration changes for mapper than owns the provider.
-
acceptJsonFormatVisitor
public void acceptJsonFormatVisitor(JavaType javaType, JsonFormatVisitorWrapper visitor) throws JsonMappingException
The method to be called byObjectMapperandObjectWriterto to expose the format of the given to to the given visitor- Parameters:
javaType- The type for which to generate formatvisitor- the visitor to accept the format- Throws:
JsonMappingException
-
generateJsonSchema
@Deprecated public JsonSchema generateJsonSchema(Class<?> type) throws JsonMappingException
Deprecated.Should not be used any moreThe method to be called byObjectMapperto generate JSON schema for given type.- Parameters:
type- The type for which to generate schema- Throws:
JsonMappingException
-
-