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

public Class BeanSerializerFactory

extends BasicSerializerFactory
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.util.*, com.fasterxml.jackson.annotation.JsonIgnoreProperties, .JsonIncludeProperties, .ObjectIdGenerator, .ObjectIdGenerators, .JsonTypeInfo.As, com.fasterxml.jackson.core.JsonGenerator, .JsonParser, .TokenStreamFactory, com.fasterxml.jackson.databind.*, com.fasterxml.jackson.databind.cfg.SerializerFactoryConfig, com.fasterxml.jackson.databind.introspect.*, com.fasterxml.jackson.databind.jsontype.NamedType, .TypeResolverBuilder, .TypeSerializer, com.fasterxml.jackson.databind.ser.impl.FilteredBeanPropertyWriter, .ObjectIdWriter, .PropertyBasedObjectIdGenerator, .UnsupportedTypeSerializer, com.fasterxml.jackson.databind.ser.std.MapSerializer, .StdDelegatingSerializer, .ToEmptyObjectSerializer, com.fasterxml.jackson.databind.type.ReferenceType, com.fasterxml.jackson.databind.util.BeanUtil, .ClassUtil, .Converter, .IgnorePropertiesUtil, .NativeImageUtil

Factory class that can provide serializers for any regular Java beans (as defined by "having at least one get method recognizable as bean accessor" -- where Object#getClass does not count); as well as for "standard" JDK types. Latter is achieved by delegating calls to BasicSerializerFactory to find serializers both for "standard" JDK types (and in some cases, sub-classes as is the case for collection classes like java.util.Lists and java.util.Maps) and bean (value) classes.

Note about delegating calls to BasicSerializerFactory: although it would be nicer to use linear delegation for construction (to essentially dispatch all calls first to the underlying BasicSerializerFactory; or alternatively after failing to provide bean-based serializer}, there is a problem: priority levels for detecting standard types are mixed. That is, we want to check if a type is a bean after some of "standard" JDK types, but before the rest. As a result, "mixed" delegation used, and calls are NOT done using regular SerializerFactory interface but rather via direct calls to BasicSerializerFactory.

Finally, since all caching is handled by the serializer provider (not factory) and there is no configurability, this factory is stateless. This means that a global singleton instance can be used.

Field Summary

Modifier and TypeField and Description
public static final BeanSerializerFactory
instance

Like BasicSerializerFactory, this factory is stateless, and thus a single shared global (== singleton) instance can be used without thread-safety issues.

private static final long
Inherited from com.fasterxml.jackson.databind.ser.BasicSerializerFactory:
_concrete_concreteLazy_factoryConfig

Constructor Summary

AccessConstructor and Description
protected
BeanSerializerFactory(SerializerFactoryConfig config)

Constructor for creating instances with specified configuration.

Method Summary

Modifier and TypeMethod and Description
protected BeanPropertyWriter
_constructWriter(SerializerProvider prov, BeanPropertyDefinition propDef, PropertyBuilder pb, boolean staticTyping, AnnotatedMember accessor)

Secondary helper method for constructing BeanPropertyWriter for given member (field or method).

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

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

Method called to construct serializer for serializing specified bean type if (but only if, as of 2.10), at least one property is found.

protected JsonSerializer<Object>
protected BeanSerializerBuilder
protected BeanPropertyWriter
constructFilteredBeanWriter(BeanPropertyWriter writer, Class<?>[] inViews)

Method called to construct a filtered writer, for given view definitions.

protected ObjectIdWriter
protected PropertyBuilder
public JsonSerializer<Object>
createSerializer(SerializerProvider
Provider that needs to be used to resolve annotation-provided serializers (but NOT for others)
prov
,
JavaType origType)

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

Main serializer constructor method.

protected Iterable<Serializers>
protected List<BeanPropertyWriter>
filterBeanProperties(SerializationConfig config, BeanDescription beanDesc, List<BeanPropertyWriter> props)

Overridable method that can filter out properties.

protected List<BeanPropertyWriter>
filterUnwantedJDKProperties(SerializationConfig config, BeanDescription beanDesc, List<BeanPropertyWriter> props)

Overridable method used to filter out specifically problematic JDK provided properties.

public JsonSerializer<Object>
findBeanOrAddOnSerializer(SerializerProvider prov, JavaType type, BeanDescription beanDesc, boolean staticTyping)

Method that will try to construct a BeanSerializer for given class if at least one property is found, OR, if not, one of add-on types.

protected List<BeanPropertyWriter>
findBeanProperties(SerializerProvider prov, BeanDescription beanDesc, BeanSerializerBuilder builder)

Method used to collect all actual serializable properties.

public JsonSerializer<Object>
public TypeSerializer

Returns:

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

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

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
,
SerializationConfig config, AnnotatedMember accessor)

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

protected boolean
isPotentialBeanType(Class<?> type)

Helper method used to skip processing for types that we know cannot be (i.e. are never consider to be) beans: things like primitives, Arrays, Enums, and proxy types.

protected void
processViews(SerializationConfig config, BeanSerializerBuilder builder)

Method called to handle view information for constructed serializer, based on bean property writers.

protected void
removeIgnorableTypes(SerializationConfig config, BeanDescription beanDesc, List<BeanPropertyDefinition> properties)

Method that will apply by-type limitations (as per [JACKSON-429]); by default this is based on com.fasterxml.jackson.annotation.JsonIgnoreType annotation but can be supplied by module-provided introspectors too.

protected List<BeanPropertyWriter>
removeOverlappingTypeIds(SerializerProvider prov, BeanDescription beanDesc, BeanSerializerBuilder builder, List<BeanPropertyWriter> props)

Helper method called to ensure that we do not have "duplicate" type ids.

protected void
removeSetterlessGetters(SerializationConfig config, BeanDescription beanDesc, List<BeanPropertyDefinition> properties)

Helper method that will remove all properties that do not have a mutator.

public SerializerFactory
withConfig(SerializerFactoryConfig config)

Implements abstract com.fasterxml.jackson.databind.ser.BasicSerializerFactory.withConfig.

Method used by module registration functionality, to attach additional serializer providers into this serializer factory.

Inherited from com.fasterxml.jackson.databind.ser.BasicSerializerFactory:
_checkMapContentInclusion_findContentSerializer_findInclusionWithContent_findKeySerializerbuildArraySerializerbuildAtomicReferenceSerializerbuildCollectionSerializerbuildCollectionSerializerbuildContainerSerializerbuildEnumSerializerbuildEnumSetSerializerbuildIndexedListSerializerbuildIterableSerializerbuildIteratorSerializerbuildMapEntrySerializerbuildMapSerializercreateKeySerializercreateKeySerializercreateTypeSerializerfindConverterfindConvertingSerializerfindFilterIdfindOptionalStdSerializerfindReferenceSerializerfindSerializerByAddonTypefindSerializerByAnnotationsfindSerializerByLookupfindSerializerByPrimaryTypefindSerializerFromAnnotationgetFactoryConfigisIndexedListusesStaticTypingwithAdditionalKeySerializerswithAdditionalSerializerswithSerializerModifier

Field Detail

instanceback to summary
public static final BeanSerializerFactory instance

Like BasicSerializerFactory, this factory is stateless, and thus a single shared global (== singleton) instance can be used without thread-safety issues.

serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

BeanSerializerFactoryback to summary
protected BeanSerializerFactory(SerializerFactoryConfig config)

Constructor for creating instances with specified configuration.

Method Detail

_constructWriterback to summary
protected BeanPropertyWriter _constructWriter(SerializerProvider prov, BeanPropertyDefinition propDef, PropertyBuilder pb, boolean staticTyping, AnnotatedMember accessor) throws JsonMappingException

Secondary helper method for constructing BeanPropertyWriter for given member (field or method).

_createSerializer2back to summary
protected JsonSerializer<?> _createSerializer2(SerializerProvider prov, JavaType type, BeanDescription beanDesc, boolean staticTyping) throws JsonMappingException
_findUnsupportedTypeSerializerback to summary
protected JsonSerializer<?> _findUnsupportedTypeSerializer(SerializerProvider ctxt, JavaType type, BeanDescription beanDesc) throws JsonMappingException
_isUnserializableJacksonTypeback to summary
protected boolean _isUnserializableJacksonType(SerializerProvider ctxt, JavaType type)
constructBeanOrAddOnSerializerback to summary
protected JsonSerializer<Object> constructBeanOrAddOnSerializer(SerializerProvider prov, JavaType type, BeanDescription beanDesc, boolean staticTyping) throws JsonMappingException

Method called to construct serializer for serializing specified bean type if (but only if, as of 2.10), at least one property is found.

Annotations
@SuppressWarnings:unchecked
Since
2.10
constructBeanSerializerback to summary
protected JsonSerializer<Object> constructBeanSerializer(SerializerProvider prov, BeanDescription beanDesc) throws JsonMappingException

Deprecated

Annotations
@Deprecated
constructBeanSerializerBuilderback to summary
protected BeanSerializerBuilder constructBeanSerializerBuilder(BeanDescription beanDesc)
constructFilteredBeanWriterback to summary
protected BeanPropertyWriter constructFilteredBeanWriter(BeanPropertyWriter writer, Class<?>[] inViews)

Method called to construct a filtered writer, for given view definitions. Default implementation constructs filter that checks active view type to views property is to be included in.

constructObjectIdHandlerback to summary
protected ObjectIdWriter constructObjectIdHandler(SerializerProvider prov, BeanDescription beanDesc, List<BeanPropertyWriter> props) throws JsonMappingException
constructPropertyBuilderback to summary
protected PropertyBuilder constructPropertyBuilder(SerializationConfig config, BeanDescription beanDesc)
createSerializerback to summary
public JsonSerializer<Object> createSerializer(SerializerProvider prov, JavaType origType) throws JsonMappingException

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

Main serializer constructor method. We will have to be careful with respect to ordering of various method calls: essentially we want to reliably figure out which classes are standard types, and which are beans. The problem is that some bean Classes may implement standard interfaces (say, java.lang.Iterable.

Note

sub-classes may choose to complete replace implementation, if they want to alter priority of serializer lookups.

Parameters
prov:SerializerProvider

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

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

Annotations
@Override
@SuppressWarnings:unchecked
customSerializersback to summary
protected Iterable<Serializers> customSerializers()

Implements abstract com.fasterxml.jackson.databind.ser.BasicSerializerFactory.customSerializers.

Annotations
@Override
filterBeanPropertiesback to summary
protected List<BeanPropertyWriter> filterBeanProperties(SerializationConfig config, BeanDescription beanDesc, List<BeanPropertyWriter> props)

Overridable method that can filter out properties. Default implementation checks annotations class may have.

filterUnwantedJDKPropertiesback to summary
protected List<BeanPropertyWriter> filterUnwantedJDKProperties(SerializationConfig config, BeanDescription beanDesc, List<BeanPropertyWriter> props)

Overridable method used to filter out specifically problematic JDK provided properties.

See issue databind-3305 for details.

Since
2.13.1
findBeanOrAddOnSerializerback to summary
public JsonSerializer<Object> findBeanOrAddOnSerializer(SerializerProvider prov, JavaType type, BeanDescription beanDesc, boolean staticTyping) throws JsonMappingException

Method that will try to construct a BeanSerializer for given class if at least one property is found, OR, if not, one of add-on types.

Note

behavior changed a bit

findBeanPropertiesback to summary
protected List<BeanPropertyWriter> findBeanProperties(SerializerProvider prov, BeanDescription beanDesc, BeanSerializerBuilder builder) throws JsonMappingException

Method used to collect all actual serializable properties. Can be overridden to implement custom detection schemes.

findBeanSerializerback to summary
public JsonSerializer<Object> findBeanSerializer(SerializerProvider prov, JavaType type, BeanDescription beanDesc) throws JsonMappingException

Deprecated

Annotations
@Deprecated
findPropertyContentTypeSerializerback to summary
public TypeSerializer findPropertyContentTypeSerializer(JavaType containerType, SerializationConfig config, AnnotatedMember accessor) throws JsonMappingException

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.

findPropertyTypeSerializerback to summary
public TypeSerializer findPropertyTypeSerializer(JavaType baseType, SerializationConfig config, AnnotatedMember accessor) throws JsonMappingException

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:JavaType

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

Returns:TypeSerializer

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

isPotentialBeanTypeback to summary
protected boolean isPotentialBeanType(Class<?> type)

Helper method used to skip processing for types that we know cannot be (i.e. are never consider to be) beans: things like primitives, Arrays, Enums, and proxy types.

Note that usually we shouldn't really be getting these sort of types anyway; but better safe than sorry.

processViewsback to summary
protected void processViews(SerializationConfig config, BeanSerializerBuilder builder)

Method called to handle view information for constructed serializer, based on bean property writers.

Note that this method is designed to be overridden by sub-classes if they want to provide custom view handling. As such it is not considered an internal implementation detail, and will be supported as part of API going forward.

removeIgnorableTypesback to summary
protected void removeIgnorableTypes(SerializationConfig config, BeanDescription beanDesc, List<BeanPropertyDefinition> properties)

Method that will apply by-type limitations (as per [JACKSON-429]); by default this is based on com.fasterxml.jackson.annotation.JsonIgnoreType annotation but can be supplied by module-provided introspectors too. Starting with 2.8 there are also "Config overrides" to consider.

removeOverlappingTypeIdsback to summary
protected List<BeanPropertyWriter> removeOverlappingTypeIds(SerializerProvider prov, BeanDescription beanDesc, BeanSerializerBuilder builder, List<BeanPropertyWriter> props)

Helper method called to ensure that we do not have "duplicate" type ids. Added to resolve [databind#222]

Since
2.6
removeSetterlessGettersback to summary
protected void removeSetterlessGetters(SerializationConfig config, BeanDescription beanDesc, List<BeanPropertyDefinition> properties)

Helper method that will remove all properties that do not have a mutator.

withConfigback to summary
public SerializerFactory withConfig(SerializerFactoryConfig config)

Implements abstract com.fasterxml.jackson.databind.ser.BasicSerializerFactory.withConfig.

Method used by module registration functionality, to attach additional serializer providers into this serializer factory. This is typically handled by constructing a new instance with additional serializers, to ensure thread-safe access.

Annotations
@Override