Top Description Fields Constructors Methods
tools.jackson.databind

public abstract Class SerializationContext

extends DatabindContext
implements ObjectWriteContext
Class Inheritance
All Implemented Interfaces
tools.jackson.core.ObjectWriteContext
Known Direct Subclasses
tools.jackson.databind.ser.SerializationContextExt
Imports
java.text.DateFormat, java.util.Date, .Locale, .Objects, .TimeZone, com.fasterxml.jackson.annotation.JsonFormat, .JsonInclude, .ObjectIdGenerator, tools.jackson.core.*, tools.jackson.core.io.CharacterEscapes, tools.jackson.core.tree.ArrayTreeNode, .ObjectTreeNode, tools.jackson.core.util.JacksonFeatureSet, tools.jackson.databind.cfg.ContextAttributes, .DatatypeFeature, .DatatypeFeatures, .DateTimeFeature, .GeneratorSettings, tools.jackson.databind.exc.InvalidDefinitionException, .InvalidTypeIdException, tools.jackson.databind.introspect.Annotated, .AnnotatedClass, .AnnotatedMember, .BeanPropertyDefinition, .ClassIntrospector, tools.jackson.databind.jsontype.TypeSerializer, tools.jackson.databind.ser.*, tools.jackson.databind.ser.impl.ReadOnlyClassToSerializerMap, .TypeWrappedSerializer, .UnknownSerializer, tools.jackson.databind.ser.std.NullSerializer, tools.jackson.databind.type.TypeFactory, tools.jackson.databind.util.ClassUtil, .TokenBuffer

Class that defines API used by ObjectMapper and ValueSerializers 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.

Field Summary

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

View used for currently active serialization, if any.

protected ContextAttributes
_attributes

Lazily-constructed holder for per-call attributes.

protected transient ClassIntrospector
_classIntrospector

Lazily constructed ClassIntrospector instance: created from "blueprint"

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 transient JsonGenerator
_generator

Token stream generator actively used; only set for per-call instances

protected final GeneratorSettings
_generatorConfig

Configuration to be used by streaming generator when it is constructed.

protected final ReadOnlyClassToSerializerMap
_knownSerializers

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

protected final ValueSerializer<Object>
_nullValueSerializer

Serializer used to output a null value.

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 final TokenStreamFactory
_streamFactory

Low-level TokenStreamFactory that may be used for constructing embedded generators.

protected JacksonFeatureSet<StreamWriteCapability>
_writeCapabilities

Capabilities of the output format.

protected static final ValueSerializer<Object>
DEFAULT_UNKNOWN_SERIALIZER

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

Constructor Summary

AccessConstructor and Description
protected
protected

Method Summary

Modifier and TypeMethod and Description
protected void
_assignGenerator(JsonGenerator
Generator to use for writing output
g
)

Method called to assign the generator to use for writing output; also updates configuration settings that depend on generator.

private ValueSerializer<Object>
protected 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>
protected DatabindException
_mappingProblem(Throwable t, String message, Object... msgArgs)

protected void
public 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 tools.jackson.databind.DatabindContext.canOverrideAccessModifiers.

Convenience method for accessing serialization view in use (if any); equivalent to:

   getConfig().canOverrideAccessModifiers();
protected ClassIntrospector
public JavaType
constructSpecializedType(JavaType baseType, Class<?> subclass)

Implements abstract tools.jackson.databind.DatabindContext.constructSpecializedType.

Convenience method for constructing subtypes, retaining generic type parameter (if any).

public ArrayTreeNode
createArrayNode()

Implements tools.jackson.core.ObjectWriteContext.createArrayNode.

Method for construct Array nodes for Tree Model instances.

public ObjectTreeNode
createObjectNode()

Implements tools.jackson.core.ObjectWriteContext.createObjectNode.

Method for construct Object nodes for Tree Model instances.

public void
defaultSerializeDateKey(long timestamp, JsonGenerator g)

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

public void
defaultSerializeDateKey(Date date, JsonGenerator g)

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

public final void
defaultSerializeDateValue(long timestamp, JsonGenerator g)

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

public final void
defaultSerializeDateValue(Date date, JsonGenerator g)

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

public final void
defaultSerializeNullValue(JsonGenerator g)

Method to call when serializing a null value (POJO property, Map entry value, Collection/array element) using configured standard mechanism.

public 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 of value.

public ValueSerializer<Object>
findContentValueSerializer(JavaType
Type of (secondary / content) values being serialized
valueType
,
BeanProperty
(optional) Property that refers to values via primary type (so type DOES NOT necessarily match valueType)
property
)

Method similar to findPrimaryPropertySerializer(JavaType, BeanProperty) but used for "content values", secondary types used by "primary" serializers for structured types like Arrays, java.util.Collections, java.util.Maps and so on.

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

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

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

public ValueSerializer<Object>
findNullKeySerializer(JavaType serializationType, BeanProperty property)

Method called to find a serializer to use for null values for given declared type.

public ValueSerializer<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 ValueSerializer<Object>
findPrimaryPropertySerializer(JavaType valueType, BeanProperty
Property that is being handled; will never be null, and its type has to match valueType parameter.
property
)

Method used for locating "primary" property value serializer (one directly handling value of the property).

public ValueSerializer<Object>
public TypeSerializer

Returns:

Type serializer to use for property values, if one is needed; null if not.
findPropertyTypeSerializer
(JavaType
Declared type to use as the base type for type information serializer
baseType
,
AnnotatedMember accessor)

Like findTypeSerializer(JavaType), but for use from specific POJO property.

public PropertyName
public PropertyName
public ValueSerializer<Object>
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.

public ValueSerializer<Object>
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.

public ValueSerializer<Object>
findTypedValueSerializer(Class<?>
Type for purpose of locating a serializer; usually dynamic runtime type, but can also be static declared type, depending on configuration
rawType
,
boolean
Whether resulting value serializer should be cached or not
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.

public ValueSerializer<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
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.

public TypeSerializer
findTypeSerializer(JavaType baseType)

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

public TypeSerializer
findTypeSerializer(JavaType baseType, AnnotatedClass classAnnotations)

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

public ValueSerializer<Object>
public ValueSerializer<Object>
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 to ValueSerializer#createContextual(SerializationContext, BeanProperty)), but caller wants to be able to do that at a later point; sometimes to avoid infinite loops

public final Class<?>
getActiveView()

Implements abstract tools.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 tools.jackson.databind.DatabindContext.getAnnotationIntrospector.

Convenience method for accessing serialization view in use (if any); equivalent to:

   getConfig().getAnnotationIntrospector();
public Object
getAttribute(Object key)

Implements abstract tools.jackson.databind.DatabindContext.getAttribute.

Method for accessing attributes available in this context.

public CharacterEscapes
public final SerializationConfig
getConfig()

Implements abstract tools.jackson.databind.DatabindContext.getConfig.

Method for accessing configuration for the serialization processing.

public final DatatypeFeatures
public ValueSerializer<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 int
public JsonGenerator
public Locale
getLocale()

Implements abstract tools.jackson.databind.DatabindContext.getLocale.

Method for accessing default Locale to use: convenience method for

   getConfig().getLocale();
public PrettyPrinter
getPrettyPrinter()

Implements tools.jackson.core.ObjectWriteContext.getPrettyPrinter.

Accessor for getting PrettyPrinter instance to use for a new generator.

public SerializableString
public FormatSchema
public int
public TimeZone
getTimeZone()

Implements abstract tools.jackson.databind.DatabindContext.getTimeZone.

Method for accessing default TimeZone to use: convenience method for

   getConfig().getTimeZone();
public final TypeFactory
public ValueSerializer<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 ValueSerializer<Object>
handlePrimaryContextualization(ValueSerializer<?> 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 contextualization, calling ValueSerializer#createContextual(SerializationContext, BeanProperty) with given property context.

public ValueSerializer<Object>
public ValueSerializer<Object>
handleSecondaryContextualization(ValueSerializer<?> 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 contextualization, calling ValueSerializer#createContextual(SerializationContext, BeanProperty) with given property context.

public boolean
hasPrettyPrinter()

Implements tools.jackson.core.ObjectWriteContext.hasPrettyPrinter.

Accessor similar to getPrettyPrinter() but which only indicates whether a non-null instance would be constructed if requested, or not.

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 BeanDescription
public DatabindException
invalidTypeIdException(JavaType baseType, String typeId, String extraDesc)

Implements abstract tools.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 tools.jackson.databind.DatabindContext.isEnabled.

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

public final boolean
isEnabled(DatatypeFeature feature)

Implements abstract tools.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 final boolean

Returns:

True if input format has specified capability; false if not
isEnabled
(StreamWriteCapability cap)

Accessor for checking whether input format has specified capability or not.

public boolean
isUnknownTypeSerializer(ValueSerializer<?> 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 <T> T
reportBadDefinition(JavaType type, String msg)

Implements abstract tools.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 tools.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)

Implements abstract tools.jackson.databind.DatabindContext.reportBadTypeDefinition.

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(Throwable t, String message, Object... msgArgs)

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

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

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

public abstract ValueSerializer<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 SerializationContext
setAttribute(Object key, Object value)

Implements abstract tools.jackson.databind.DatabindContext.setAttribute.

Method for setting per-call value of given attribute.

public TokenStreamFactory
public abstract <
Actual node type; usually either basic JsonNode or tools.jackson.databind.node.ObjectNode
T extends JsonNode
>
T

Returns:

(non-null) Root node of the resulting content tree: in case of null value node for which JsonNode#isNull() returns true.
valueToTree
(Object
Java value to convert
fromValue
)

Method that will convert given Java value (usually bean) into its equivalent Tree mode JsonNode representation.

public void
public void
writeValue(JsonGenerator gen, Object value)

Implements tools.jackson.core.ObjectWriteContext.writeValue.

Method that may be called to serialize given value, using specified token stream generator.

Inherited from tools.jackson.databind.DatabindContext:
_colonConcat_desc_format_quotedString_throwNotASubtype_throwSubtypeClassNotAllowed_throwSubtypeNameNotAllowed_truncateconstructTypeconverterInstanceintrospectBeanDescriptionintrospectClassAnnotationsintrospectClassAnnotationsintrospectDirectClassAnnotationsisAnnotationProcessingEnabledlazyIntrospectBeanDescriptionobjectIdGeneratorInstanceobjectIdResolverInstancereportBadDefinitionreportBadTypeDefinitionresolveAndValidateSubTyperesolveSubType