Top Description Fields Constructors Methods
tools.jackson.databind.ser

public abstract Class BasicSerializerFactory

extends SerializerFactory
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Known Direct Subclasses
tools.jackson.databind.ser.BeanSerializerFactory
Annotations
@SuppressWarnings:serial
Imports
java.net.InetAddress, .InetSocketAddress, java.nio.ByteBuffer, java.nio.file.Path, java.util.*, java.util.concurrent.atomic.AtomicReference, java.util.stream.DoubleStream, .IntStream, .LongStream, .Stream, com.fasterxml.jackson.annotation.*, tools.jackson.databind.*, tools.jackson.databind.annotation.JsonSerialize, tools.jackson.databind.cfg.SerializerFactoryConfig, tools.jackson.databind.ext.OptionalHandlerFactory, tools.jackson.databind.ext.jdk8.*, tools.jackson.databind.introspect.*, tools.jackson.databind.jsontype.TypeSerializer, tools.jackson.databind.ser.jackson.JacksonSerializableSerializer, .JsonValueSerializer, tools.jackson.databind.ser.jdk.*, tools.jackson.databind.ser.std.*, tools.jackson.databind.type.*, tools.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 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 ValueSerializer<?>
_buildReferenceSerializer(SerializationContext ctxt, Class<?> baseType, ReferenceType refType, BeanDescription.Supplier beanDescRef, boolean staticTyping, TypeSerializer contentTypeSerializer, ValueSerializer<Object> contentSerializer)

protected JsonFormat.Value
_calculateEffectiveFormat(SerializationContext ctxt, BeanDescription.Supplier beanDescRef, Class<?> baseType, JsonFormat.Value formatOverrides)

Helper method that will combine all available pieces of format configuration and calculate effective format settings to use.

protected MapSerializer
_checkMapContentInclusion(SerializationContext ctxt, BeanDescription.Supplier beanDescRef, MapSerializer mapSer)

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

protected ValueSerializer<Object>
_findContentSerializer(SerializationContext ctxt, 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(SerializationContext ctxt, BeanDescription.Supplier beanDescRef, 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 ValueSerializer<Object>
_findKeySerializer(SerializationContext ctxt, 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(BeanDescription
the bean description to remove Enum properties from.
beanDesc
)

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

protected ValueSerializer<?>
buildArraySerializer(SerializationContext ctxt, ArrayType type, BeanDescription.Supplier beanDescRef, JsonFormat.Value formatOverrides, boolean staticTyping, TypeSerializer elementTypeSerializer, ValueSerializer<Object> elementValueSerializer)

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

protected ValueSerializer<?>
buildCollectionSerializer(SerializationContext ctxt, CollectionType type, BeanDescription.Supplier beanDescRef, JsonFormat.Value formatOverrides, boolean staticTyping, TypeSerializer elementTypeSerializer, ValueSerializer<Object> elementValueSerializer)

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

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

protected ValueSerializer<?>
buildContainerSerializer(SerializationContext ctxt, JavaType type, BeanDescription.Supplier beanDescRef, JsonFormat.Value formatOverrides, boolean staticTyping)

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

protected ValueSerializer<?>
buildIterableSerializer(SerializationContext ctxt, JavaType type, BeanDescription.Supplier beanDescRef, JsonFormat.Value effectiveFormat, boolean staticTyping, JavaType valueType)

protected ValueSerializer<?>
buildIteratorSerializer(SerializationContext ctxt, JavaType type, BeanDescription.Supplier beanDesc, JsonFormat.Value formatOverrides, boolean staticTyping, JavaType valueType)

protected ValueSerializer<?>
buildMapEntrySerializer(SerializationContext ctxt, JavaType type, BeanDescription.Supplier beanDescRef, JsonFormat.Value effectiveFormat, boolean staticTyping, JavaType keyType, JavaType valueType)

protected ValueSerializer<?>
buildMapSerializer(SerializationContext ctxt, MapType type, BeanDescription.Supplier beanDescRef, JsonFormat.Value formatOverrides, boolean staticTyping, ValueSerializer<Object> keySerializer, TypeSerializer elementTypeSerializer, ValueSerializer<Object> elementValueSerializer)

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

public ValueSerializer<Object>
createKeySerializer(SerializationContext ctxt, JavaType keyType)

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

protected Iterable<Serializers>
protected Converter<Object, Object>
protected ValueSerializer<?>
findConvertingSerializer(SerializationContext ctxt, Annotated a, ValueSerializer<?> 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.Supplier beanDescRef)

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

public TypeSerializer

Returns:

Type serializer to use for property value contents, if one is needed; null if not.
findPropertyContentTypeSerializer
(SerializationContext ctxt, JavaType
Declared type of the container to use as the base type for type information serializer
containerType
,
AnnotatedMember accessor)

Method called to create a type information serializer for values of given container property if one is needed.

public ValueSerializer<?>
protected final ValueSerializer<?>
findSerializerByAddonType(SerializationContext ctxt, JavaType javaType, BeanDescription.Supplier beanDescRef, JsonFormat.Value formatOverrides, boolean staticTyping)

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

protected final ValueSerializer<?>
findSerializerByAnnotations(SerializationContext ctxt, JavaType type, BeanDescription.Supplier beanDescRef)

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

protected final ValueSerializer<?>
findSerializerByPrimaryType(SerializationContext ctxt, JavaType type, BeanDescription.Supplier beanDescRef, JsonFormat.Value formatOverrides, 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 ValueSerializer<Object>
findSerializerFromAnnotation(SerializationContext ctxt, Annotated a)

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

public ValueSerializer<Object>
getDefaultNullKeySerializer()

Implements abstract tools.jackson.databind.ser.SerializerFactory.getDefaultNullKeySerializer.

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

public ValueSerializer<Object>
protected boolean
protected boolean
usesStaticTyping(SerializationConfig config, BeanDescription.Supplier beanDescRef)

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 tools.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 tools.jackson.databind.ser.SerializerFactory.withAdditionalSerializers.

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

protected abstract SerializerFactory
withConfig(SerializerFactoryConfig config)

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

public final SerializerFactory
public final SerializerFactory
public final SerializerFactory
withSerializerModifier(ValueSerializerModifier modifier)

Implements abstract tools.jackson.databind.ser.SerializerFactory.withSerializerModifier.

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

Inherited from tools.jackson.databind.ser.SerializerFactory:
createSerializercreateSerializer

Field Detail

_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

_buildReferenceSerializerback to summary
protected ValueSerializer<?> _buildReferenceSerializer(SerializationContext ctxt, Class<?> baseType, ReferenceType refType, BeanDescription.Supplier beanDescRef, boolean staticTyping, TypeSerializer contentTypeSerializer, ValueSerializer<Object> contentSerializer)
_calculateEffectiveFormatback to summary
protected JsonFormat.Value _calculateEffectiveFormat(SerializationContext ctxt, BeanDescription.Supplier beanDescRef, Class<?> baseType, JsonFormat.Value formatOverrides)

Helper method that will combine all available pieces of format configuration and calculate effective format settings to use.

Since
3.0
_checkMapContentInclusionback to summary
protected MapSerializer _checkMapContentInclusion(SerializationContext ctxt, BeanDescription.Supplier beanDescRef, MapSerializer mapSer)

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

_findContentSerializerback to summary
protected ValueSerializer<Object> _findContentSerializer(SerializationContext ctxt, Annotated a)

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(SerializationContext ctxt, BeanDescription.Supplier beanDescRef, JavaType contentType, Class<?> configType)

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 ValueSerializer<Object> _findKeySerializer(SerializationContext ctxt, Annotated a)

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(BeanDescription 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 references.

Parameters
beanDesc:BeanDescription

the bean description to remove Enum properties from.

Since
2.16
buildArraySerializerback to summary
protected ValueSerializer<?> buildArraySerializer(SerializationContext ctxt, ArrayType type, BeanDescription.Supplier beanDescRef, JsonFormat.Value formatOverrides, boolean staticTyping, TypeSerializer elementTypeSerializer, ValueSerializer<Object> elementValueSerializer)

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

buildCollectionSerializerback to summary
protected ValueSerializer<?> buildCollectionSerializer(SerializationContext ctxt, CollectionType type, BeanDescription.Supplier beanDescRef, JsonFormat.Value formatOverrides, boolean staticTyping, TypeSerializer elementTypeSerializer, ValueSerializer<Object> elementValueSerializer)

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

buildCollectionSerializerback to summary
public StdContainerSerializer<?> buildCollectionSerializer(JavaType elemType, boolean staticTyping, TypeSerializer vts, ValueSerializer<Object> valueSerializer)
buildContainerSerializerback to summary
protected ValueSerializer<?> buildContainerSerializer(SerializationContext ctxt, JavaType type, BeanDescription.Supplier beanDescRef, JsonFormat.Value formatOverrides, boolean staticTyping)
buildEnumSerializerback to summary
protected ValueSerializer<?> buildEnumSerializer(SerializationContext ctxt, JavaType type, BeanDescription.Supplier beanDescRef, JsonFormat.Value effectiveFormat)
buildEnumSetSerializerback to summary
public ValueSerializer<?> buildEnumSetSerializer(JavaType enumType)
buildIndexedListSerializerback to summary
public StdContainerSerializer<?> buildIndexedListSerializer(JavaType elemType, boolean staticTyping, TypeSerializer vts, ValueSerializer<Object> valueSerializer)
buildIterableSerializerback to summary
protected ValueSerializer<?> buildIterableSerializer(SerializationContext ctxt, JavaType type, BeanDescription.Supplier beanDescRef, JsonFormat.Value effectiveFormat, boolean staticTyping, JavaType valueType)
buildIteratorSerializerback to summary
protected ValueSerializer<?> buildIteratorSerializer(SerializationContext ctxt, JavaType type, BeanDescription.Supplier beanDesc, JsonFormat.Value formatOverrides, boolean staticTyping, JavaType valueType)
buildMapEntrySerializerback to summary
protected ValueSerializer<?> buildMapEntrySerializer(SerializationContext ctxt, JavaType type, BeanDescription.Supplier beanDescRef, JsonFormat.Value effectiveFormat, boolean staticTyping, JavaType keyType, JavaType valueType)
buildMapSerializerback to summary
protected ValueSerializer<?> buildMapSerializer(SerializationContext ctxt, MapType type, BeanDescription.Supplier beanDescRef, JsonFormat.Value formatOverrides, boolean staticTyping, ValueSerializer<Object> keySerializer, TypeSerializer elementTypeSerializer, ValueSerializer<Object> elementValueSerializer)

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

createKeySerializerback to summary
public ValueSerializer<Object> createKeySerializer(SerializationContext ctxt, JavaType keyType)

Implements abstract tools.jackson.databind.ser.SerializerFactory.createKeySerializer.

Doc from tools.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)

Annotations
@Override
@SuppressWarnings:unchecked
customSerializersback to summary
protected Iterable<Serializers> customSerializers()
findConverterback to summary
protected Converter<Object, Object> findConverter(SerializationContext ctxt, Annotated a)
findConvertingSerializerback to summary
protected ValueSerializer<?> findConvertingSerializer(SerializationContext ctxt, Annotated a, ValueSerializer<?> 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. If not, will simply return given serializer as is.

findFilterIdback to summary
protected Object findFilterId(SerializationConfig config, BeanDescription.Supplier beanDescRef)

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

findPropertyContentTypeSerializerback to summary
public TypeSerializer findPropertyContentTypeSerializer(SerializationContext ctxt, JavaType containerType, AnnotatedMember accessor)

Method called to create a type information serializer for values of given container property if one is needed. If not needed (no polymorphic handling configured), should return null.

Parameters
containerType:JavaType

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

Returns:TypeSerializer

Type serializer to use for property value contents, if one is needed; null if not.

findReferenceSerializerback to summary
public ValueSerializer<?> findReferenceSerializer(SerializationContext ctxt, ReferenceType refType, BeanDescription.Supplier beanDesc, JsonFormat.Value format, boolean staticTyping)
findSerializerByAddonTypeback to summary
protected final ValueSerializer<?> findSerializerByAddonType(SerializationContext ctxt, JavaType javaType, BeanDescription.Supplier beanDescRef, JsonFormat.Value formatOverrides, boolean staticTyping)

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 ValueSerializer<?> findSerializerByAnnotations(SerializationContext ctxt, JavaType type, BeanDescription.Supplier beanDescRef)

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

Currently handles things like:

findSerializerByPrimaryTypeback to summary
protected final ValueSerializer<?> findSerializerByPrimaryType(SerializationContext ctxt, JavaType type, BeanDescription.Supplier beanDescRef, JsonFormat.Value formatOverrides, 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). This does not include "secondary" interfaces, but mostly concrete or abstract base classes.

findSerializerFromAnnotationback to summary
protected ValueSerializer<Object> findSerializerFromAnnotation(SerializationContext ctxt, Annotated a)

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

Annotations
@SuppressWarnings:unchecked
getDefaultNullKeySerializerback to summary
public ValueSerializer<Object> getDefaultNullKeySerializer()

Implements abstract tools.jackson.databind.ser.SerializerFactory.getDefaultNullKeySerializer.

Doc from tools.jackson.databind.ser.SerializerFactory.getDefaultNullKeySerializer.

Returns serializer used to (try to) output a null key, due to an entry of java.util.Map having null key. The default implementation will throw an exception if this happens; alternative implementation (like one that would write an Empty String) can be defined.

Annotations
@Override
getDefaultNullValueSerializerback to summary
public ValueSerializer<Object> getDefaultNullValueSerializer()

Implements abstract tools.jackson.databind.ser.SerializerFactory.getDefaultNullValueSerializer.

Annotations
@Override
isIndexedListback to summary
protected boolean isIndexedList(Class<?> cls)
usesStaticTypingback to summary
protected boolean usesStaticTyping(SerializationConfig config, BeanDescription.Supplier beanDescRef)

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).

withAdditionalKeySerializersback to summary
public final SerializerFactory withAdditionalKeySerializers(Serializers additional)

Implements abstract tools.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 tools.jackson.databind.ser.SerializerFactory.withAdditionalSerializers.

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

Annotations
@Override
withConfigback to summary
protected 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 tools.jackson.databind.ser.BeanSerializerFactory for more details.

withNullKeySerializerback to summary
public final SerializerFactory withNullKeySerializer(ValueSerializer<?> nks)

Implements abstract tools.jackson.databind.ser.SerializerFactory.withNullKeySerializer.

Annotations
@Override
withNullValueSerializerback to summary
public final SerializerFactory withNullValueSerializer(ValueSerializer<?> nvs)

Implements abstract tools.jackson.databind.ser.SerializerFactory.withNullValueSerializer.

Annotations
@Override
withSerializerModifierback to summary
public final SerializerFactory withSerializerModifier(ValueSerializerModifier modifier)

Implements abstract tools.jackson.databind.ser.SerializerFactory.withSerializerModifier.

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

Annotations
@Override