- All Implemented Interfaces:
ObjectWriteContext
- Direct Known Subclasses:
SerializationContextExt
ObjectMapper
and
ValueSerializer
s 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.
NOTE: In Jackson 2.x this class was called SerializerProvider
.
-
Nested Class Summary
Nested classes/interfaces inherited from interface tools.jackson.core.ObjectWriteContext
ObjectWriteContext.Base
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Class<?>
View used for currently active serialization, if any.protected ContextAttributes
Lazily-constructed holder for per-call attributes.protected ClassIntrospector
Lazily constructedClassIntrospector
instance: created from "blueprint"protected final SerializationConfig
Serialization configuration to use for serialization processing.protected DateFormat
Lazily acquired and instantiated formatter object: initialized first time it is needed, reused afterwards.protected JsonGenerator
Token stream generator actively used; only set for per-call instancesprotected final GeneratorSettings
Configuration to be used by streaming generator when it is constructed.protected final ReadOnlyClassToSerializerMap
For fast lookups, we will have a local non-shared read-only map that contains serializers previously fetched.protected final ValueSerializer<Object>
Serializer used to output a null value.protected final SerializerCache
Cache for doing type-to-value-serializer lookups.protected final SerializerFactory
Factory used for constructing actual serializer instances.protected final boolean
Flag set to indicate that we are using vanilla null value serializationprotected final TokenStreamFactory
Low-levelTokenStreamFactory
that may be used for constructing embedded generators.protected JacksonFeatureSet<StreamWriteCapability>
Capabilities of the output format.protected static final ValueSerializer<Object>
Placeholder serializer used whenjava.lang.Object
typed property is marked to be serialized. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
SerializationContext
(TokenStreamFactory streamFactory, SerializationConfig config, GeneratorSettings generatorConfig, SerializerFactory f, SerializerCache cache) protected
SerializationContext
(SerializationContext src, SerializerCache serializerCache) -
Method Summary
Modifier and TypeMethodDescriptionprotected ValueSerializer<Object>
_createAndCachePropertySerializer
(Class<?> rawType, JavaType fullType, BeanProperty prop) Alternative to_createAndCacheUntypedSerializer(Class, JavaType)
, used when serializer is requested for given property.protected ValueSerializer<Object>
_createAndCachePropertySerializer
(JavaType type, BeanProperty prop) Alternative to_createAndCacheUntypedSerializer(JavaType)
, used when serializer is requested for given property.protected ValueSerializer<Object>
_createAndCacheUntypedSerializer
(Class<?> rawType, JavaType fullType) Method that will try to construct a value serializer; and if one is successfully created, cache it for reuse.protected ValueSerializer<Object>
protected final DateFormat
protected ValueSerializer<Object>
_handleResolvable
(ValueSerializer<?> ser) protected DatabindException
_mappingProblem
(Throwable t, String message, Object... msgArgs) protected void
_reportIncompatibleRootType
(Object value, JavaType rootType) Specialized factory method used when we are converting values and do not typically have or use "real" parsers or generators.final boolean
Convenience method for accessing serialization view in use (if any); equivalent to:protected ClassIntrospector
constructSpecializedType
(JavaType baseType, Class<?> subclass) Convenience method for constructing subtypes, retaining generic type parameter (if any).void
defaultSerializeDateKey
(long timestamp, JsonGenerator g) Method that will handle serialization of Dates used asMap
keys, based onDateTimeFeature.WRITE_DATE_KEYS_AS_TIMESTAMPS
value (and if using textual representation, configured date format)void
defaultSerializeDateKey
(Date date, JsonGenerator g) Method that will handle serialization of Dates used asMap
keys, based onDateTimeFeature.WRITE_DATE_KEYS_AS_TIMESTAMPS
value (and if using textual representation, configured date format)final void
defaultSerializeDateValue
(long timestamp, JsonGenerator g) Method that will handle serialization of Date(-like) values, usingSerializationConfig
settings to determine expected serialization behavior.final void
defaultSerializeDateValue
(Date date, JsonGenerator g) Method that will handle serialization of Date(-like) values, usingSerializationConfig
settings to determine expected serialization behavior.final void
Method to call when serializing anull
value (POJO property, Map entry value, Collection/array element) using configured standard mechanism.final void
defaultSerializeProperty
(String propertyName, Object value, JsonGenerator g) Convenience method that will serialize given property with specified value, using the default serializer for runtime type ofvalue
.findContentValueSerializer
(Class<?> rawType, BeanProperty property) findContentValueSerializer
(JavaType valueType, BeanProperty property) Method similar tofindPrimaryPropertySerializer(JavaType, BeanProperty)
but used for "content values", secondary types used by "primary" serializers for structured types like Arrays,Collection
s,Map
s and so on.findKeySerializer
(Class<?> rawKeyType, BeanProperty property) findKeySerializer
(JavaType keyType, BeanProperty property) Method called to get the serializer to use for serializing non-null Map keys.findNullKeySerializer
(JavaType serializationType, BeanProperty property) Method called to find a serializer to use for null values for given declared type.findNullValueSerializer
(BeanProperty property) Method called to get the serializer to use for serializing null values for specified property.abstract WritableObjectId
findObjectId
(Object forPojo, ObjectIdGenerator<?> generatorType) Method called to find the Object Id for given POJO, if one has been generated.findPrimaryPropertySerializer
(Class<?> rawType, BeanProperty property) findPrimaryPropertySerializer
(JavaType valueType, BeanProperty property) Method used for locating "primary" property value serializer (one directly handling value of the property).findPropertyTypeSerializer
(JavaType baseType, AnnotatedMember accessor) LikefindTypeSerializer(JavaType)
, but for use from specific POJO property.findRootName
(Class<?> rawRootType) findRootName
(JavaType rootType) findRootValueSerializer
(Class<?> rawType) Method for finding (from cache) or creating (and caching) serializer for given type, without checking for polymorphic typing, and then contextualizing without actual property.findRootValueSerializer
(JavaType valueType) Method for finding (from cache) or creating (and caching) serializer for given type, without checking for polymorphic typing, and then contextualizing without actual property.findTypedValueSerializer
(Class<?> rawType, boolean cache) Method called to locate regular serializer, matching type serializer, and if both found, wrap them in a serializer that calls both in correct sequence.findTypedValueSerializer
(JavaType valueType, boolean cache) Method called to locate regular serializer, matching type serializer, and if both found, wrap them in a serializer that calls both in correct sequence.findTypeSerializer
(JavaType baseType) Method called to get theTypeSerializer
to use for including Type Id necessary for serializing for the given Java class.findTypeSerializer
(JavaType baseType, AnnotatedClass classAnnotations) Method called to get theTypeSerializer
to use for including Type Id necessary for serializing for the given Java class.findValueSerializer
(Class<?> rawType) findValueSerializer
(JavaType valueType) Method variant used when we do NOT want contextualization to happen; it will need to be done at a later point (many serializers are not in operational state before contextualization, call toValueSerializer.createContextual(SerializationContext, BeanProperty)
), but caller wants to be able to do that at a later point; sometimes to avoid infinite loopsfinal Class<?>
Accessor for locating currently active view, if any; returns null if no view has been set.final AnnotationIntrospector
Convenience method for accessing serialization view in use (if any); equivalent to:getAttribute
(Object key) Method for accessing attributes available in this context.final SerializationConfig
Method for accessing configuration for the serialization processing.final DatatypeFeatures
final JsonFormat.Value
getDefaultPropertyFormat
(Class<?> baseType) final JsonInclude.Value
getDefaultPropertyInclusion
(Class<?> baseType) final FilterProvider
Convenience method for accessing provider to find serialization filters used, equivalent to calling:int
getFormatWriteFeatures
(int defaults) Method for accessing default Locale to use: convenience method forgetRootValueSeparator
(SerializableString defaultSeparator) int
getStreamWriteFeatures
(int defaults) Method for accessing default TimeZone to use: convenience method forfinal TypeFactory
getUnknownTypeSerializer
(Class<?> unknownType) Method called to get the serializer to use if provider cannot determine an actual type-specific serializer to use; typically when none ofSerializerFactory
instances are able to construct a serializer.handlePrimaryContextualization
(ValueSerializer<?> ser, BeanProperty property) Method called for primary property serializers (ones directly created to serialize values of a POJO property), to handle details of contextualization, callingValueSerializer.createContextual(SerializationContext, BeanProperty)
with given property context.handleSecondaryContextualization
(ValueSerializer<?> ser, BeanProperty 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 contextualization, callingValueSerializer.createContextual(SerializationContext, BeanProperty)
with given property context.boolean
final boolean
hasSerializationFeatures
(int featureMask) "Bulk" access method for checking that all features specified by mask are enabled.abstract Object
includeFilterInstance
(BeanPropertyDefinition forProperty, Class<?> filterClass) Method that can be called to construct and configureJsonInclude
filter instance, given aClass
to instantiate (with default constructor, by default).abstract boolean
includeFilterSuppressNulls
(Object filter) Follow-up method that may be called after callingincludeFilterInstance(tools.jackson.databind.introspect.BeanPropertyDefinition, java.lang.Class<?>)
, to check handling of `null` values by the filter.introspectBeanDescription
(JavaType type, AnnotatedClass ac) invalidTypeIdException
(JavaType baseType, String typeId, String extraDesc) Helper method for constructing exception to indicate that given type id could not be resolved to a valid subtype of specified base type.final boolean
Accessor for checking whether input format has specified capability or not.final boolean
isEnabled
(DatatypeFeature feature) Method for checking whether specified datatype feature is enabled or not.final boolean
isEnabled
(MapperFeature feature) Convenience method for checking whether specified Mapper feature is enabled or not.final boolean
isEnabled
(SerializationFeature feature) Convenience method for checking whether specified serialization feature is enabled or not.boolean
Helper method called to see if given serializer is considered to be something returned bygetUnknownTypeSerializer(java.lang.Class<?>)
, that is, something for which no regular serializer was found or constructed.<T> T
reportBadDefinition
(Class<?> raw, String msg, Throwable cause) <T> T
reportBadDefinition
(JavaType type, String msg) 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 aInvalidDefinitionException
.<T> T
reportBadDefinition
(JavaType type, String msg, Throwable cause) <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.<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.void
reportMappingProblem
(String message, Object... msgArgs) Helper method called to indicate problem; default behavior is to construct and throw aDatabindException
, but in future may collect more than one and only throw after certain number, or at the end of serialization.void
reportMappingProblem
(Throwable t, String message, Object... msgArgs) Helper method called to indicate problem; default behavior is to construct and throw aDatabindException
, but in future may collect more than one and only throw after certain number, or at the end of serialization.abstract ValueSerializer<Object>
serializerInstance
(Annotated annotated, Object serDef) Method that can be called to construct and configure serializer instance, either given aClass
to instantiate (with default constructor), or an uninitialized serializer instance.setAttribute
(Object key, Object value) Method for setting per-call value of given attribute.abstract <T extends JsonNode>
TvalueToTree
(Object fromValue) Method that will convert given Java value (usually bean) into its equivalent Tree modeJsonNode
representation.void
writeTree
(JsonGenerator gen, TreeNode tree) void
writeValue
(JsonGenerator gen, Object value) Methods inherited from class tools.jackson.databind.DatabindContext
_colonConcat, _desc, _format, _quotedString, _throwNotASubtype, _throwSubtypeClassNotAllowed, _throwSubtypeNameNotAllowed, _truncate, constructType, converterInstance, introspectBeanDescription, introspectClassAnnotations, introspectClassAnnotations, introspectDirectClassAnnotations, isAnnotationProcessingEnabled, lazyIntrospectBeanDescription, objectIdGeneratorInstance, objectIdResolverInstance, reportBadDefinition, reportBadTypeDefinition, resolveAndValidateSubType, resolveSubType
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface tools.jackson.core.ObjectWriteContext
createGenerator, createGenerator, createGenerator
-
Field Details
-
DEFAULT_UNKNOWN_SERIALIZER
Placeholder serializer used whenjava.lang.Object
typed property is marked to be serialized.
NOTE: starting with 2.6, this instance is NOT used for any other types, and separate instances are constructed for "empty" Beans. -
_config
Serialization configuration to use for serialization processing. -
_generatorConfig
Configuration to be used by streaming generator when it is constructed.- Since:
- 3.0
-
_streamFactory
Low-levelTokenStreamFactory
that may be used for constructing embedded generators. -
_generator
Token stream generator actively used; only set for per-call instances- Since:
- 3.0
-
_writeCapabilities
Capabilities of the output format.- Since:
- 3.0
-
_activeView
View used for currently active serialization, if any. -
_serializerFactory
Factory used for constructing actual serializer instances. Only set for non-blueprint instances. -
_nullValueSerializer
Serializer used to output a null value. Default implementation writes nulls usingJsonGenerator.writeNull()
. -
_stdNullValueSerializer
protected final boolean _stdNullValueSerializerFlag set to indicate that we are using vanilla null value serialization -
_serializerCache
Cache for doing type-to-value-serializer lookups. -
_knownSerializers
For fast lookups, we will have a local non-shared read-only map that contains serializers previously fetched. -
_dateFormat
Lazily acquired and instantiated formatter object: initialized first time it is needed, reused afterwards. Used via instances (not blueprints), so that access need not be thread-safe. -
_classIntrospector
Lazily constructedClassIntrospector
instance: created from "blueprint" -
_attributes
Lazily-constructed holder for per-call attributes. Only set for non-blueprint instances.
-
-
Constructor Details
-
SerializationContext
protected SerializationContext(TokenStreamFactory streamFactory, SerializationConfig config, GeneratorSettings generatorConfig, SerializerFactory f, SerializerCache cache) -
SerializationContext
-
-
Method Details
-
tokenStreamFactory
- Specified by:
tokenStreamFactory
in interfaceObjectWriteContext
-
getSchema
- Specified by:
getSchema
in interfaceObjectWriteContext
-
getCharacterEscapes
- Specified by:
getCharacterEscapes
in interfaceObjectWriteContext
-
getPrettyPrinter
- Specified by:
getPrettyPrinter
in interfaceObjectWriteContext
-
hasPrettyPrinter
public boolean hasPrettyPrinter()- Specified by:
hasPrettyPrinter
in interfaceObjectWriteContext
-
getRootValueSeparator
- Specified by:
getRootValueSeparator
in interfaceObjectWriteContext
-
getStreamWriteFeatures
public int getStreamWriteFeatures(int defaults) - Specified by:
getStreamWriteFeatures
in interfaceObjectWriteContext
-
getFormatWriteFeatures
public int getFormatWriteFeatures(int defaults) - Specified by:
getFormatWriteFeatures
in interfaceObjectWriteContext
-
createArrayNode
- Specified by:
createArrayNode
in interfaceObjectWriteContext
-
createObjectNode
- Specified by:
createObjectNode
in interfaceObjectWriteContext
-
writeValue
- Specified by:
writeValue
in interfaceObjectWriteContext
- Throws:
JacksonException
-
writeTree
- Specified by:
writeTree
in interfaceObjectWriteContext
- Throws:
JacksonException
-
getConfig
Method for accessing configuration for the serialization processing.- Specified by:
getConfig
in classDatabindContext
-
getAnnotationIntrospector
Description copied from class:DatabindContext
Convenience method for accessing serialization view in use (if any); equivalent to:getConfig().getAnnotationIntrospector();
- Specified by:
getAnnotationIntrospector
in classDatabindContext
-
getTypeFactory
- Specified by:
getTypeFactory
in classDatabindContext
-
constructSpecializedType
public JavaType constructSpecializedType(JavaType baseType, Class<?> subclass) throws IllegalArgumentException Description copied from class:DatabindContext
Convenience method for constructing subtypes, retaining generic type parameter (if any).Note: since 2.11 handling has varied a bit across serialization, deserialization.
- Specified by:
constructSpecializedType
in classDatabindContext
- Throws:
IllegalArgumentException
-
getActiveView
Description copied from class:DatabindContext
Accessor for locating currently active view, if any; returns null if no view has been set.- Specified by:
getActiveView
in classDatabindContext
-
canOverrideAccessModifiers
public final boolean canOverrideAccessModifiers()Description copied from class:DatabindContext
Convenience method for accessing serialization view in use (if any); equivalent to:getConfig().canOverrideAccessModifiers();
- Specified by:
canOverrideAccessModifiers
in classDatabindContext
-
isEnabled
Description copied from class:DatabindContext
Convenience method for checking whether specified Mapper feature is enabled or not. Shortcut for:getConfig().isEnabled(feature);
- Specified by:
isEnabled
in classDatabindContext
-
isEnabled
Description copied from class:DatabindContext
Method for checking whether specified datatype feature is enabled or not.- Specified by:
isEnabled
in classDatabindContext
-
getDatatypeFeatures
- Specified by:
getDatatypeFeatures
in classDatabindContext
-
getDefaultPropertyFormat
- Specified by:
getDefaultPropertyFormat
in classDatabindContext
-
getDefaultPropertyInclusion
-
getLocale
Method for accessing default Locale to use: convenience method forgetConfig().getLocale();
- Specified by:
getLocale
in classDatabindContext
-
getTimeZone
Method for accessing default TimeZone to use: convenience method forgetConfig().getTimeZone();
- Specified by:
getTimeZone
in classDatabindContext
-
classIntrospector
- Specified by:
classIntrospector
in classDatabindContext
-
introspectBeanDescription
- Specified by:
introspectBeanDescription
in classDatabindContext
-
findRootName
- Specified by:
findRootName
in classDatabindContext
-
findRootName
- Specified by:
findRootName
in classDatabindContext
-
getAttribute
Description copied from class:DatabindContext
Method for accessing attributes available in this context. Per-call attributes have highest precedence; attributes set viaObjectReader
orObjectWriter
have lower precedence.- Specified by:
getAttribute
in classDatabindContext
- Parameters:
key
- Key of the attribute to get- Returns:
- Value of the attribute, if any; null otherwise
-
setAttribute
Description copied from class:DatabindContext
Method for setting per-call value of given attribute. This will override any previously defined value for the attribute within this context.- Specified by:
setAttribute
in classDatabindContext
- Parameters:
key
- Key of the attribute to setvalue
- Value to set attribute to- Returns:
- This context object, to allow chaining
-
isEnabled
Convenience method for checking whether specified serialization feature is enabled or not. Shortcut for:getConfig().isEnabled(feature);
-
hasSerializationFeatures
public final boolean hasSerializationFeatures(int featureMask) "Bulk" access method for checking that all features specified by mask are enabled. -
isEnabled
Accessor for checking whether input format has specified capability or not.- Returns:
- True if input format has specified capability; false if not
-
getFilterProvider
Convenience method for accessing provider to find serialization filters used, equivalent to calling:getConfig().getFilterProvider();
-
getGenerator
-
bufferForValueConversion
Specialized factory method used when we are converting values and do not typically have or use "real" parsers or generators. -
findObjectId
Method 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. -
findTypedValueSerializer
Method called to locate regular serializer, matching type serializer, and if both found, wrap them in a serializer that calls both in correct sequence. This method is mostly used for root-level serializer handling to allow for simpler caching. A call can always be replaced by equivalent calls to access serializer and type serializer separately. Note: contextualization (call toValueSerializer.createContextual(tools.jackson.databind.SerializationContext, tools.jackson.databind.BeanProperty)
) is done before returning theValueSerializer
.- Parameters:
rawType
- Type for purpose of locating a serializer; usually dynamic runtime type, but can also be static declared type, depending on configurationcache
- Whether resulting value serializer should be cached or not
-
findTypedValueSerializer
Method called to locate regular serializer, matching type serializer, and if both found, wrap them in a serializer that calls both in correct sequence. This method is mostly used for root-level serializer handling to allow for simpler caching. A call can always be replaced by equivalent calls to access serializer and type serializer separately. Note: contextualization (call toValueSerializer.createContextual(tools.jackson.databind.SerializationContext, tools.jackson.databind.BeanProperty)
) is done before returning theValueSerializer
.- Parameters:
valueType
- 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)cache
- Whether resulting value serializer should be cached or not
-
findRootValueSerializer
Method for finding (from cache) or creating (and caching) serializer for given type, without checking for polymorphic typing, and then contextualizing without actual property. This is most often used for root-level values (when writing sequences), but may sometimes be used for more esoteric value handling for delegation. Note: contextualization (call toValueSerializer.createContextual(tools.jackson.databind.SerializationContext, tools.jackson.databind.BeanProperty)
) is done before returning theValueSerializer
.- Since:
- 3.0
-
findRootValueSerializer
Method for finding (from cache) or creating (and caching) serializer for given type, without checking for polymorphic typing, and then contextualizing without actual property. This is most often used for root-level values (when writing sequences), but may sometimes be used for more esoteric value handling for delegation. Note: contextualization (call toValueSerializer.createContextual(tools.jackson.databind.SerializationContext, tools.jackson.databind.BeanProperty)
) is done before returning theValueSerializer
.- Since:
- 3.0
-
findPrimaryPropertySerializer
public ValueSerializer<Object> findPrimaryPropertySerializer(JavaType valueType, BeanProperty property) Method used for locating "primary" property value serializer (one directly handling value of the property). Difference (if any) has to do with contextual resolution, and method(s) called: this method should only be called when caller is certain that this is the primary property value serializer. Contextualization (call toValueSerializer.createContextual(SerializationContext, BeanProperty)
will be done before returning theValueSerializer
.- Parameters:
property
- Property that is being handled; will never be null, and its type has to matchvalueType
parameter.
-
findPrimaryPropertySerializer
public ValueSerializer<Object> findPrimaryPropertySerializer(Class<?> rawType, BeanProperty property) -
findContentValueSerializer
public ValueSerializer<Object> findContentValueSerializer(JavaType valueType, BeanProperty property) Method similar tofindPrimaryPropertySerializer(JavaType, BeanProperty)
but used for "content values", secondary types used by "primary" serializers for structured types like Arrays,Collection
s,Map
s and so on.Serializer will be contextualized, but will not have type serializer wrapped.
- Parameters:
valueType
- Type of (secondary / content) values being serializedproperty
- (optional) Property that refers to values via primary type (so type DOES NOT necessarily matchvalueType
)
-
findContentValueSerializer
-
findValueSerializer
- See Also:
-
findValueSerializer
Method variant used when we do NOT want contextualization to happen; it will need to be done at a later point (many serializers are not in operational state before contextualization, call toValueSerializer.createContextual(SerializationContext, BeanProperty)
), but caller wants to be able to do that at a later point; sometimes to avoid infinite loops -
findTypeSerializer
Method called to get theTypeSerializer
to use for including Type Id necessary for serializing for the given Java class. Useful for schema generators. -
findTypeSerializer
Method called to get theTypeSerializer
to use for including Type Id necessary for serializing for the given Java class. Useful for schema generators.- Since:
- 3.0
-
findPropertyTypeSerializer
LikefindTypeSerializer(JavaType)
, but for use from specific POJO property. Method called to create a type information serializer for values of given non-container property if one is needed. If not needed (no polymorphic handling configured), should return null.- Parameters:
baseType
- Declared type to use as the base type for type information serializer- Returns:
- Type serializer to use for property values, if one is needed; null if not.
- Since:
- 3.0
-
findKeySerializer
Method called to get the serializer to use for serializing non-null Map keys. Separation from regularfindValueSerializer(java.lang.Class<?>)
method is because actual write method must be different (@link JsonGenerator#writeName}; but also since behavior for some key types may differ.Note that the serializer itself can be called with instances of any Java object, but not nulls.
-
findKeySerializer
-
getDefaultNullValueSerializer
-
findNullKeySerializer
public ValueSerializer<Object> findNullKeySerializer(JavaType serializationType, BeanProperty property) Method called to find a serializer to use for null values for given declared type. Note that type is completely based on declared type, since nulls in Java have no type and thus runtime type cannot be determined. -
findNullValueSerializer
Method called to get the serializer to use for serializing null values for specified property.Default implementation simply calls
getDefaultNullValueSerializer()
; can be overridden to add custom null serialization for properties of certain type or name. This gives method full granularity to basically override null handling for any specific property or class of properties. -
getUnknownTypeSerializer
Method called to get the serializer to use if provider cannot determine an actual type-specific serializer to use; typically when none ofSerializerFactory
instances are able to construct a serializer.Typically, returned serializer will throw an exception, although alternatively
ToStringSerializer
could be returned as well.- Parameters:
unknownType
- Type for which no serializer is found
-
isUnknownTypeSerializer
Helper method called to see if given serializer is considered to be something returned bygetUnknownTypeSerializer(java.lang.Class<?>)
, that is, something for which no regular serializer was found or constructed. -
_createAndCacheUntypedSerializer
protected ValueSerializer<Object> _createAndCacheUntypedSerializer(Class<?> rawType, JavaType fullType) Method that will try to construct a value serializer; and if one is successfully created, cache it for reuse. -
_createAndCacheUntypedSerializer
-
_createAndCachePropertySerializer
protected ValueSerializer<Object> _createAndCachePropertySerializer(Class<?> rawType, JavaType fullType, BeanProperty prop) Alternative to_createAndCacheUntypedSerializer(Class, JavaType)
, used when serializer is requested for given property. -
_createAndCachePropertySerializer
protected ValueSerializer<Object> _createAndCachePropertySerializer(JavaType type, BeanProperty prop) Alternative to_createAndCacheUntypedSerializer(JavaType)
, used when serializer is requested for given property. -
_handleResolvable
-
serializerInstance
Method that can be called to construct and configure serializer instance, either given aClass
to instantiate (with default constructor), or an uninitialized serializer instance. Either way, serializer will be properly resolved (viaValueSerializer.resolve(tools.jackson.databind.SerializationContext)
).- Parameters:
annotated
- Annotated entity that contained definitionserDef
- Serializer definition: either an instance or class
-
includeFilterInstance
public abstract Object includeFilterInstance(BeanPropertyDefinition forProperty, Class<?> filterClass) Method that can be called to construct and configureJsonInclude
filter instance, given aClass
to instantiate (with default constructor, by default).- Parameters:
forProperty
- (optional) If filter is created for a property, that property; `null` if filter created via defaulting, global or per-type.
-
includeFilterSuppressNulls
Follow-up method that may be called after callingincludeFilterInstance(tools.jackson.databind.introspect.BeanPropertyDefinition, java.lang.Class<?>)
, to check handling of `null` values by the filter. -
handlePrimaryContextualization
public ValueSerializer<Object> handlePrimaryContextualization(ValueSerializer<?> ser, BeanProperty property) Method called for primary property serializers (ones directly created to serialize values of a POJO property), to handle details of contextualization, callingValueSerializer.createContextual(SerializationContext, BeanProperty)
with given property context.- Parameters:
property
- Property for which the given primary serializer is used; never null.
-
handleSecondaryContextualization
public ValueSerializer<Object> handleSecondaryContextualization(ValueSerializer<?> ser, BeanProperty 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 contextualization, callingValueSerializer.createContextual(SerializationContext, BeanProperty)
with given property context. Given that these serializers are not directly related to given property (or, in case of root value property, to any property), annotations accessible may or may not be relevant.- Parameters:
property
- Property for which serializer is used, if any; null when deserializing root values
-
handleRootContextualization
- Since:
- 3.0
-
defaultSerializeProperty
public final void defaultSerializeProperty(String propertyName, Object value, JsonGenerator g) throws JacksonException Convenience method that will serialize given property with specified value, using the default serializer for runtime type ofvalue
.- Throws:
JacksonException
-
defaultSerializeDateValue
public final void defaultSerializeDateValue(long timestamp, JsonGenerator g) throws JacksonException Method that will handle serialization of Date(-like) values, usingSerializationConfig
settings to determine expected serialization behavior. Note: date here means "full" date, that is, date AND time, as per Java convention (and not date-only values like in SQL)- Throws:
JacksonException
-
defaultSerializeDateValue
Method that will handle serialization of Date(-like) values, usingSerializationConfig
settings to determine expected serialization behavior. Note: date here means "full" date, that is, date AND time, as per Java convention (and not date-only values like in SQL)- Throws:
JacksonException
-
defaultSerializeDateKey
Method that will handle serialization of Dates used asMap
keys, based onDateTimeFeature.WRITE_DATE_KEYS_AS_TIMESTAMPS
value (and if using textual representation, configured date format)- Throws:
JacksonException
-
defaultSerializeDateKey
Method that will handle serialization of Dates used asMap
keys, based onDateTimeFeature.WRITE_DATE_KEYS_AS_TIMESTAMPS
value (and if using textual representation, configured date format)- Throws:
JacksonException
-
defaultSerializeNullValue
Method to call when serializing anull
value (POJO property, Map entry value, Collection/array element) using configured standard mechanism. Note that this does NOT consider filtering any more as value is expected.- Throws:
JacksonException
- Since:
- 3.0 (in 2.x was called
defaultSerializeNull
)
-
valueToTree
Method that will convert given Java value (usually bean) into its equivalent Tree modeJsonNode
representation. Functionally similar to serializing value into token stream and parsing that stream back as tree model node, but more efficient asTokenBuffer
is used to contain the intermediate representation instead of fully serialized contents.NOTE: while results are usually identical to that of serialization followed by deserialization, this is not always the case. In some cases serialization into intermediate representation will retain encapsulation of things like raw value (
RawValue
) or basic node identity (JsonNode
). If so, result is a valid tree, but values are not re-constructed through actual format representation. So if transformation requires actual materialization of encoded content, it will be necessary to do actual serialization.- Type Parameters:
T
- Actual node type; usually either basicJsonNode
orObjectNode
- Parameters:
fromValue
- Java value to convert- Returns:
- (non-null) Root node of the resulting content tree: in case of
null
value node for whichJsonNode.isNull()
returnstrue
. - Throws:
JacksonException
-
reportBadTypeDefinition
public <T> T reportBadTypeDefinition(BeanDescription bean, String msg, Object... msgArgs) throws DatabindException Helper method called to indicate problem in POJO (serialization) definitions or settings regarding specific Java type, unrelated to actual JSON content to map. Default behavior is to construct and throw aInvalidDefinitionException
.- Specified by:
reportBadTypeDefinition
in classDatabindContext
- Throws:
DatabindException
-
reportBadPropertyDefinition
public <T> T reportBadPropertyDefinition(BeanDescription bean, BeanPropertyDefinition prop, String message, Object... msgArgs) throws DatabindException 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. Default behavior is to construct and throw aInvalidDefinitionException
.- Throws:
DatabindException
-
reportBadDefinition
Description copied from class:DatabindContext
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 aInvalidDefinitionException
.- Specified by:
reportBadDefinition
in classDatabindContext
- Throws:
DatabindException
-
reportBadDefinition
public <T> T reportBadDefinition(JavaType type, String msg, Throwable cause) throws DatabindException - Throws:
DatabindException
-
reportBadDefinition
public <T> T reportBadDefinition(Class<?> raw, String msg, Throwable cause) throws DatabindException - Throws:
DatabindException
-
reportMappingProblem
public void reportMappingProblem(Throwable t, String message, Object... msgArgs) throws DatabindException Helper method called to indicate problem; default behavior is to construct and throw aDatabindException
, but in future may collect more than one and only throw after certain number, or at the end of serialization.- Throws:
DatabindException
-
_mappingProblem
-
reportMappingProblem
Helper method called to indicate problem; default behavior is to construct and throw aDatabindException
, but in future may collect more than one and only throw after certain number, or at the end of serialization.- Throws:
DatabindException
-
invalidTypeIdException
Description copied from class:DatabindContext
Helper method for constructing exception to indicate that given type id could not be resolved to a valid subtype of specified base type. Most commonly called during polymorphic deserialization.Note that most of the time this method should NOT be called directly: instead, method
handleUnknownTypeId()
should be called which will call this method if necessary.- Specified by:
invalidTypeIdException
in classDatabindContext
-
_reportIncompatibleRootType
- Throws:
JacksonException
-
_dateFormat
-