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

public abstract Class BasicSerializerFactory

extends SerializerFactory
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Known Direct Subclasses
com.fasterxml.jackson.databind.ser.BeanSerializerFactory
Annotations
@SuppressWarnings:serial
Imports
java.math.BigDecimal, .BigInteger, java.net.InetAddress, .InetSocketAddress, java.nio.ByteBuffer, java.util.*, java.util.concurrent.atomic.AtomicReference, com.fasterxml.jackson.annotation.JsonFormat, .JsonIgnoreProperties, .JsonInclude, .JsonIncludeProperties, com.fasterxml.jackson.databind.*, com.fasterxml.jackson.databind.annotation.JsonSerialize, com.fasterxml.jackson.databind.cfg.SerializerFactoryConfig, com.fasterxml.jackson.databind.ext.OptionalHandlerFactory, com.fasterxml.jackson.databind.introspect.*, com.fasterxml.jackson.databind.jsontype.NamedType, .TypeResolverBuilder, .TypeSerializer, com.fasterxml.jackson.databind.ser.impl.*, com.fasterxml.jackson.databind.ser.std.*, com.fasterxml.jackson.databind.type.*, com.fasterxml.jackson.databind.util.*

Factory class that can provide serializers for standard JDK classes, as well as custom classes that extend standard classes or implement one of "well-known" interfaces (such as java.util.Collection).

Since all the serializers are eagerly instantiated, and there is no additional introspection or customizability of these types, this factory is essentially stateless.

Field Summary

Modifier and TypeField and Description
protected static final HashMap<String, JsonSerializer<?>>
_concrete

Since these are all JDK classes, we shouldn't have to worry about ClassLoader used to load them.

protected static final HashMap<String, Class<? extends JsonSerializer<?>>>
_concreteLazy

Actually it may not make much sense to eagerly instantiate all kinds of serializers: so this Map actually contains class references, not instances

protected final SerializerFactoryConfig
_factoryConfig

Configuration settings for this factory; immutable instance (just like this factory), new version created via copy-constructor (fluent-style)

Constructor Summary

AccessConstructor and Description
protected
BasicSerializerFactory(SerializerFactoryConfig config)

We will provide default constructor to allow sub-classing, but make it protected so that no non-singleton instances of the class will be instantiated.

Method Summary

Modifier and TypeMethod and Description
protected MapSerializer
_checkMapContentInclusion(SerializerProvider prov, BeanDescription beanDesc, MapSerializer mapSer)

Deprecated as a consequence of MapSerializer being deprecated.
Helper method that does figures out content inclusion value to use, if any, and construct re-configured MapSerializer appropriately.
protected JsonSerializer<Object>
_findContentSerializer(SerializerProvider prov, Annotated a)

Helper method called to try to find whether there is an annotation in the class that indicates content ("value") serializer to use.

protected JsonInclude.Value
_findInclusionWithContent(SerializerProvider prov, BeanDescription beanDesc, JavaType
Declared full content type of container
contentType
,
Class<?>
Raw base type under which `configOverride`, if any, needs to be defined
configType
)

Helper method used for finding inclusion definitions for structured container types like Maps and referential types (like AtomicReference).

protected JsonSerializer<Object>
_findKeySerializer(SerializerProvider prov, Annotated a)

Helper method called to try to find whether there is an annotation in the class that indicates key serializer to use.

private void
_removeEnumSelfReferences(BasicBeanDescription
the bean description to remove Enum properties from.
beanDesc
)

Helper method used for serialization Enum as JsonFormat.Shape#OBJECT.

protected JsonSerializer<?>
buildArraySerializer(SerializerProvider prov, ArrayType type, BeanDescription beanDesc, boolean staticTyping, TypeSerializer elementTypeSerializer, JsonSerializer<Object> elementValueSerializer)

Helper method that handles configuration details when constructing serializers for Object[] (and subtypes, except for String).

protected JsonSerializer<?>
buildAtomicReferenceSerializer(SerializerProvider prov, ReferenceType refType, BeanDescription beanDesc, boolean staticTyping, TypeSerializer contentTypeSerializer, JsonSerializer<Object> contentSerializer)

protected JsonSerializer<?>
buildCollectionSerializer(SerializerProvider prov, CollectionType type, BeanDescription beanDesc, boolean staticTyping, TypeSerializer elementTypeSerializer, JsonSerializer<Object> elementValueSerializer)

Helper method that handles configuration details when constructing serializers for java.util.List types that support efficient by-index access

public ContainerSerializer<?>
buildCollectionSerializer(JavaType elemType, boolean staticTyping, TypeSerializer vts, JsonSerializer<Object> valueSerializer)

Deprecated as a consequence of ContainerSerializer being deprecated.
protected JsonSerializer<?>
buildContainerSerializer(SerializerProvider prov, JavaType type, BeanDescription beanDesc, boolean staticTyping)

protected JsonSerializer<?>
public JsonSerializer<?>
public ContainerSerializer<?>
buildIndexedListSerializer(JavaType elemType, boolean staticTyping, TypeSerializer vts, JsonSerializer<Object> valueSerializer)

Deprecated as a consequence of ContainerSerializer being deprecated.
protected JsonSerializer<?>
buildIterableSerializer(SerializationConfig config, JavaType type, BeanDescription beanDesc, boolean staticTyping, JavaType valueType)

protected JsonSerializer<?>
buildIteratorSerializer(SerializationConfig config, JavaType type, BeanDescription beanDesc, boolean staticTyping, JavaType valueType)

protected JsonSerializer<?>
buildMapEntrySerializer(SerializerProvider prov, JavaType type, BeanDescription beanDesc, boolean staticTyping, JavaType keyType, JavaType valueType)

protected JsonSerializer<?>
buildMapSerializer(SerializerProvider prov, MapType type, BeanDescription beanDesc, boolean staticTyping, JsonSerializer<Object> keySerializer, TypeSerializer elementTypeSerializer, JsonSerializer<Object> elementValueSerializer)

Helper method that handles configuration details when constructing serializers for java.util.Map types.

public JsonSerializer<Object>
createKeySerializer(SerializerProvider ctxt, JavaType
Declared type for Map keys
keyType
,
JsonSerializer<Object>
Default key serializer implementation to use, if no custom ones are found (may be null)
defaultImpl
)

Overrides com.fasterxml.jackson.databind.ser.SerializerFactory.createKeySerializer.

Method called to create serializer to use for serializing JSON property names (which must be output as JsonToken.FIELD_NAME) for Map that has specified declared key type, and is for specified property (or, if property is null, as root value)
public JsonSerializer<Object>
public abstract JsonSerializer<Object>
createSerializer(SerializerProvider
Provider that needs to be used to resolve annotation-provided serializers (but NOT for others)
prov
,
JavaType type)

Implements abstract com.fasterxml.jackson.databind.ser.SerializerFactory.createSerializer.

Method called to create (or, for immutable serializers, reuse) a serializer for given type.
public TypeSerializer
createTypeSerializer(SerializationConfig config, JavaType
Declared type to use as the base type for type information serializer
baseType
)

Implements abstract com.fasterxml.jackson.databind.ser.SerializerFactory.createTypeSerializer.

Method called to construct a type serializer for values with given declared base type.
protected abstract Iterable<Serializers>
protected Converter<Object, Object>
protected JsonSerializer<?>
findConvertingSerializer(SerializerProvider prov, Annotated a, JsonSerializer<?> ser)

Helper method that will check whether given annotated entity (usually class, but may also be a property accessor) indicates that a Converter is to be used; and if so, to construct and return suitable serializer for it.

protected Object
findFilterId(SerializationConfig config, BeanDescription beanDesc)

Method called to find filter that is configured to be used with bean serializer being built, if any.

protected JsonSerializer<?>
findOptionalStdSerializer(SerializerProvider prov, JavaType type, BeanDescription beanDesc, boolean staticTyping)

Overridable method called after checking all other types.

public JsonSerializer<?>
findReferenceSerializer(SerializerProvider prov, ReferenceType refType, BeanDescription beanDesc, boolean staticTyping)

protected final JsonSerializer<?>
findSerializerByAddonType(SerializationConfig config, JavaType javaType, BeanDescription beanDesc, boolean staticTyping)

Reflection-based serialized find method, which checks if given class implements one of recognized "add-on" interfaces.

protected final JsonSerializer<?>
findSerializerByAnnotations(SerializerProvider prov, JavaType type, BeanDescription beanDesc)

Method called to see if one of primary per-class annotations (or related, like implementing of JsonSerializable) determines the serializer to use.

protected final JsonSerializer<?>
findSerializerByLookup(JavaType type, SerializationConfig config, BeanDescription beanDesc, boolean staticTyping)

Method that will use fast lookup (and identity comparison) methods to see if we know serializer to use for given type.

protected final JsonSerializer<?>
findSerializerByPrimaryType(SerializerProvider prov, JavaType type, BeanDescription beanDesc, boolean staticTyping)

Method for checking if we can determine serializer to use based on set of known primary types, checking for set of known base types (exact matches having been compared against with findSerializerByLookup).

protected JsonSerializer<Object>
findSerializerFromAnnotation(SerializerProvider prov, Annotated a)

Helper method called to check if a class or method has an annotation (@link com.fasterxml.jackson.databind.annotation.JsonSerialize#using) that tells the class to use for serialization.

public SerializerFactoryConfig
getFactoryConfig()

Method for getting current SerializerFactoryConfig.

protected boolean
protected boolean
usesStaticTyping(SerializationConfig config, BeanDescription beanDesc)

Helper method to check whether global settings and/or class annotations for the bean class indicate that static typing (declared types) should be used for properties.

public final SerializerFactory
withAdditionalKeySerializers(Serializers additional)

Implements abstract com.fasterxml.jackson.databind.ser.SerializerFactory.withAdditionalKeySerializers.

Convenience method for creating a new factory instance with an additional key serializer provider.
public final SerializerFactory
withAdditionalSerializers(Serializers additional)

Implements abstract com.fasterxml.jackson.databind.ser.SerializerFactory.withAdditionalSerializers.

Convenience method for creating a new factory instance with an additional serializer provider.
public abstract SerializerFactory
withConfig(SerializerFactoryConfig config)

Method used for creating a new instance of this factory, but with different configuration.

public final SerializerFactory
withSerializerModifier(BeanSerializerModifier modifier)

Implements abstract com.fasterxml.jackson.databind.ser.SerializerFactory.withSerializerModifier.

Convenience method for creating a new factory instance with additional bean serializer modifier.

Field Detail

_concreteback to summary
protected static final HashMap<String, JsonSerializer<?>> _concrete

Since these are all JDK classes, we shouldn't have to worry about ClassLoader used to load them. Rather, we can just use the class name, and keep things simple and efficient.

_concreteLazyback to summary
protected static final HashMap<String, Class<? extends JsonSerializer<?>>> _concreteLazy

Actually it may not make much sense to eagerly instantiate all kinds of serializers: so this Map actually contains class references, not instances

_factoryConfigback to summary
protected final SerializerFactoryConfig _factoryConfig

Configuration settings for this factory; immutable instance (just like this factory), new version created via copy-constructor (fluent-style)

Constructor Detail

BasicSerializerFactoryback to summary
protected BasicSerializerFactory(SerializerFactoryConfig config)

We will provide default constructor to allow sub-classing, but make it protected so that no non-singleton instances of the class will be instantiated.

Method Detail

_checkMapContentInclusionback to summary
protected MapSerializer _checkMapContentInclusion(SerializerProvider prov, BeanDescription beanDesc, MapSerializer mapSer) throws JsonMappingException

Deprecated

as a consequence of MapSerializer being deprecated. See corresponding docs for further information.

Helper method that does figures out content inclusion value to use, if any, and construct re-configured MapSerializer appropriately.

Annotations
@SuppressWarnings:deprecation
Since
2.9
_findContentSerializerback to summary
protected JsonSerializer<Object> _findContentSerializer(SerializerProvider prov, Annotated a) throws JsonMappingException

Helper method called to try to find whether there is an annotation in the class that indicates content ("value") serializer to use. If so, will try to instantiate value serializer and return it; otherwise returns null.

_findInclusionWithContentback to summary
protected JsonInclude.Value _findInclusionWithContent(SerializerProvider prov, BeanDescription beanDesc, JavaType contentType, Class<?> configType) throws JsonMappingException

Helper method used for finding inclusion definitions for structured container types like Maps and referential types (like AtomicReference).

Parameters
contentType:JavaType

Declared full content type of container

configType:Class<?>

Raw base type under which `configOverride`, if any, needs to be defined

_findKeySerializerback to summary
protected JsonSerializer<Object> _findKeySerializer(SerializerProvider prov, Annotated a) throws JsonMappingException

Helper method called to try to find whether there is an annotation in the class that indicates key serializer to use. If so, will try to instantiate key serializer and return it; otherwise returns null.

_removeEnumSelfReferencesback to summary
private void _removeEnumSelfReferences(BasicBeanDescription beanDesc)

Helper method used for serialization Enum as JsonFormat.Shape#OBJECT. Removes any self-referencing properties from its bean description before it is transformed into a JSON Object as configured by JsonFormat.Shape#OBJECT.

Internally, this method iterates through BeanDescription#findProperties() and removes self.

Parameters
beanDesc:BasicBeanDescription

the bean description to remove Enum properties from.

Since
2.16
buildArraySerializerback to summary
protected JsonSerializer<?> buildArraySerializer(SerializerProvider prov, ArrayType type, BeanDescription beanDesc, boolean staticTyping, TypeSerializer elementTypeSerializer, JsonSerializer<Object> elementValueSerializer) throws JsonMappingException

Helper method that handles configuration details when constructing serializers for Object[] (and subtypes, except for String).

buildAtomicReferenceSerializerback to summary
protected JsonSerializer<?> buildAtomicReferenceSerializer(SerializerProvider prov, ReferenceType refType, BeanDescription beanDesc, boolean staticTyping, TypeSerializer contentTypeSerializer, JsonSerializer<Object> contentSerializer) throws JsonMappingException
buildCollectionSerializerback to summary
protected JsonSerializer<?> buildCollectionSerializer(SerializerProvider prov, CollectionType type, BeanDescription beanDesc, boolean staticTyping, TypeSerializer elementTypeSerializer, JsonSerializer<Object> elementValueSerializer) throws JsonMappingException

Helper method that handles configuration details when constructing serializers for java.util.List types that support efficient by-index access

Since
2.1
buildCollectionSerializerback to summary
public ContainerSerializer<?> buildCollectionSerializer(JavaType elemType, boolean staticTyping, TypeSerializer vts, JsonSerializer<Object> valueSerializer)

Deprecated

as a consequence of ContainerSerializer being deprecated. See corresponding docs for further information.

buildContainerSerializerback to summary
protected JsonSerializer<?> buildContainerSerializer(SerializerProvider prov, JavaType type, BeanDescription beanDesc, boolean staticTyping) throws JsonMappingException
Since
2.1
buildEnumSerializerback to summary
protected JsonSerializer<?> buildEnumSerializer(SerializationConfig config, JavaType type, BeanDescription beanDesc) throws JsonMappingException
buildEnumSetSerializerback to summary
public JsonSerializer<?> buildEnumSetSerializer(JavaType enumType)
buildIndexedListSerializerback to summary
public ContainerSerializer<?> buildIndexedListSerializer(JavaType elemType, boolean staticTyping, TypeSerializer vts, JsonSerializer<Object> valueSerializer)

Deprecated

as a consequence of ContainerSerializer being deprecated. See corresponding docs for further information.

buildIterableSerializerback to summary
protected JsonSerializer<?> buildIterableSerializer(SerializationConfig config, JavaType type, BeanDescription beanDesc, boolean staticTyping, JavaType valueType) throws JsonMappingException
Since
2.5
buildIteratorSerializerback to summary
protected JsonSerializer<?> buildIteratorSerializer(SerializationConfig config, JavaType type, BeanDescription beanDesc, boolean staticTyping, JavaType valueType) throws JsonMappingException
Since
2.5
buildMapEntrySerializerback to summary
protected JsonSerializer<?> buildMapEntrySerializer(SerializerProvider prov, JavaType type, BeanDescription beanDesc, boolean staticTyping, JavaType keyType, JavaType valueType) throws JsonMappingException
Since
2.9
buildMapSerializerback to summary
protected JsonSerializer<?> buildMapSerializer(SerializerProvider prov, MapType type, BeanDescription beanDesc, boolean staticTyping, JsonSerializer<Object> keySerializer, TypeSerializer elementTypeSerializer, JsonSerializer<Object> elementValueSerializer) throws JsonMappingException

Helper method that handles configuration details when constructing serializers for java.util.Map types.

createKeySerializerback to summary
public JsonSerializer<Object> createKeySerializer(SerializerProvider ctxt, JavaType keyType, JsonSerializer<Object> defaultImpl) throws JsonMappingException

Overrides com.fasterxml.jackson.databind.ser.SerializerFactory.createKeySerializer.

Doc from com.fasterxml.jackson.databind.ser.SerializerFactory.createKeySerializer.

Method called to create serializer to use for serializing JSON property names (which must be output as JsonToken.FIELD_NAME) for Map that has specified declared key type, and is for specified property (or, if property is null, as root value)

Parameters
keyType:JavaType

Declared type for Map keys

defaultImpl:JsonSerializer<Object>

Default key serializer implementation to use, if no custom ones are found (may be null)

Returns:JsonSerializer<Object>

Serializer to use, if factory knows it; null if not (in which case default serializer is to be used)

Annotations
@Override
@SuppressWarnings:unchecked
createKeySerializerback to summary
public JsonSerializer<Object> createKeySerializer(SerializationConfig config, JavaType keyType, JsonSerializer<Object> defaultImpl)

Implements abstract com.fasterxml.jackson.databind.ser.SerializerFactory.createKeySerializer.

Deprecated

Annotations
@Override
@SuppressWarnings:unchecked
@Deprecated
createSerializerback to summary
public abstract JsonSerializer<Object> createSerializer(SerializerProvider prov, JavaType type) throws JsonMappingException

Implements abstract com.fasterxml.jackson.databind.ser.SerializerFactory.createSerializer.

Doc from com.fasterxml.jackson.databind.ser.SerializerFactory.createSerializer.

Method called to create (or, for immutable serializers, reuse) a serializer for given type.

Parameters
prov:SerializerProvider

Provider that needs to be used to resolve annotation-provided serializers (but NOT for others)

Annotations
@Override
createTypeSerializerback to summary
public TypeSerializer createTypeSerializer(SerializationConfig config, JavaType baseType)

Implements abstract com.fasterxml.jackson.databind.ser.SerializerFactory.createTypeSerializer.

Method called to construct a type serializer for values with given declared base type. This is called for values other than those of bean property types.

Parameters
baseType:JavaType

Doc from com.fasterxml.jackson.databind.ser.SerializerFactory.createTypeSerializer.

Declared type to use as the base type for type information serializer

Returns:TypeSerializer

Doc from com.fasterxml.jackson.databind.ser.SerializerFactory.createTypeSerializer.

Type serializer to use for the base type, if one is needed; null if not.

Annotations
@Override
customSerializersback to summary
protected abstract Iterable<Serializers> customSerializers()
findConverterback to summary
protected Converter<Object, Object> findConverter(SerializerProvider prov, Annotated a) throws JsonMappingException
findConvertingSerializerback to summary
protected JsonSerializer<?> findConvertingSerializer(SerializerProvider prov, Annotated a, JsonSerializer<?> ser) throws JsonMappingException

Helper method that will check whether given annotated entity (usually class, but may also be a property accessor) indicates that a Converter is to be used; and if so, to construct and return suitable serializer for it. If not, will simply return given serializer as is.

findFilterIdback to summary
protected Object findFilterId(SerializationConfig config, BeanDescription beanDesc)

Method called to find filter that is configured to be used with bean serializer being built, if any.

findOptionalStdSerializerback to summary
protected JsonSerializer<?> findOptionalStdSerializer(SerializerProvider prov, JavaType type, BeanDescription beanDesc, boolean staticTyping) throws JsonMappingException

Overridable method called after checking all other types.

Since
2.2
findReferenceSerializerback to summary
public JsonSerializer<?> findReferenceSerializer(SerializerProvider prov, ReferenceType refType, BeanDescription beanDesc, boolean staticTyping) throws JsonMappingException
Since
2.7
findSerializerByAddonTypeback to summary
protected final JsonSerializer<?> findSerializerByAddonType(SerializationConfig config, JavaType javaType, BeanDescription beanDesc, boolean staticTyping) throws JsonMappingException

Reflection-based serialized find method, which checks if given class implements one of recognized "add-on" interfaces. Add-on here means a role that is usually or can be a secondary trait: for example, bean classes may implement Iterable, but their main function is usually something else. The reason for

findSerializerByAnnotationsback to summary
protected final JsonSerializer<?> findSerializerByAnnotations(SerializerProvider prov, JavaType type, BeanDescription beanDesc) throws JsonMappingException

Method called to see if one of primary per-class annotations (or related, like implementing of JsonSerializable) determines the serializer to use.

Currently handles things like:

Since
2.0
findSerializerByLookupback to summary
protected final JsonSerializer<?> findSerializerByLookup(JavaType type, SerializationConfig config, BeanDescription beanDesc, boolean staticTyping)

Method that will use fast lookup (and identity comparison) methods to see if we know serializer to use for given type.

findSerializerByPrimaryTypeback to summary
protected final JsonSerializer<?> findSerializerByPrimaryType(SerializerProvider prov, JavaType type, BeanDescription beanDesc, boolean staticTyping) throws JsonMappingException

Method for checking if we can determine serializer to use based on set of known primary types, checking for set of known base types (exact matches having been compared against with findSerializerByLookup). This does not include "secondary" interfaces, but mostly concrete or abstract base classes.

findSerializerFromAnnotationback to summary
protected JsonSerializer<Object> findSerializerFromAnnotation(SerializerProvider prov, Annotated a) throws JsonMappingException

Helper method called to check if a class or method has an annotation (@link com.fasterxml.jackson.databind.annotation.JsonSerialize#using) that tells the class to use for serialization. Returns null if no such annotation found.

Annotations
@SuppressWarnings:unchecked
getFactoryConfigback to summary
public SerializerFactoryConfig getFactoryConfig()

Method for getting current SerializerFactoryConfig.

Note that since instances are immutable, you can NOT change settings by accessing an instance and calling methods: this will simply create new instance of config object.

isIndexedListback to summary
protected boolean isIndexedList(Class<?> cls)
usesStaticTypingback to summary
protected boolean usesStaticTyping(SerializationConfig config, BeanDescription beanDesc)

Helper method to check whether global settings and/or class annotations for the bean class indicate that static typing (declared types) should be used for properties. (instead of dynamic runtime types).

Since
2.16 (earlier had variant with additional 'typeSer' parameter)
withAdditionalKeySerializersback to summary
public final SerializerFactory withAdditionalKeySerializers(Serializers additional)

Implements abstract com.fasterxml.jackson.databind.ser.SerializerFactory.withAdditionalKeySerializers.

Convenience method for creating a new factory instance with an additional key serializer provider.

Annotations
@Override
withAdditionalSerializersback to summary
public final SerializerFactory withAdditionalSerializers(Serializers additional)

Implements abstract com.fasterxml.jackson.databind.ser.SerializerFactory.withAdditionalSerializers.

Convenience method for creating a new factory instance with an additional serializer provider.

Annotations
@Override
withConfigback to summary
public abstract SerializerFactory withConfig(SerializerFactoryConfig config)

Method used for creating a new instance of this factory, but with different configuration. Reason for specifying factory method (instead of plain constructor) is to allow proper sub-classing of factories.

Note that custom sub-classes generally must override implementation of this method, as it usually requires instantiating a new instance of factory type. Check out javadocs for com.fasterxml.jackson.databind.ser.BeanSerializerFactory for more details.

withSerializerModifierback to summary
public final SerializerFactory withSerializerModifier(BeanSerializerModifier modifier)

Implements abstract com.fasterxml.jackson.databind.ser.SerializerFactory.withSerializerModifier.

Convenience method for creating a new factory instance with additional bean serializer modifier.

Annotations
@Override