public class BeanSerializerFactory extends BasicSerializerFactory implements Serializable
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
List
s and Map
s) 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.
Modifier and Type | Field and Description |
---|---|
static BeanSerializerFactory |
instance
Like
BasicSerializerFactory , this factory is stateless, and
thus a single shared global (== singleton) instance can be used
without thread-safety issues. |
_concrete, _concreteLazy, _factoryConfig
Modifier | Constructor and Description |
---|---|
protected |
BeanSerializerFactory(SerializerFactoryConfig config)
Constructor for creating instances with specified configuration.
|
Modifier and Type | Method 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<?> |
_findUnsupportedTypeSerializer(SerializerProvider ctxt,
JavaType type,
BeanDescription beanDesc) |
protected boolean |
_isUnserializableJacksonType(SerializerProvider ctxt,
JavaType type) |
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> |
constructBeanSerializer(SerializerProvider prov,
BeanDescription beanDesc)
Deprecated.
|
protected BeanSerializerBuilder |
constructBeanSerializerBuilder(BeanDescription beanDesc) |
protected BeanPropertyWriter |
constructFilteredBeanWriter(BeanPropertyWriter writer,
Class<?>[] inViews)
Method called to construct a filtered writer, for given view
definitions.
|
protected ObjectIdWriter |
constructObjectIdHandler(SerializerProvider prov,
BeanDescription beanDesc,
List<BeanPropertyWriter> props) |
protected PropertyBuilder |
constructPropertyBuilder(SerializationConfig config,
BeanDescription beanDesc) |
JsonSerializer<Object> |
createSerializer(SerializerProvider prov,
JavaType origType)
Main serializer constructor method.
|
protected Iterable<Serializers> |
customSerializers() |
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.
|
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.
|
JsonSerializer<Object> |
findBeanSerializer(SerializerProvider prov,
JavaType type,
BeanDescription beanDesc)
Deprecated.
|
TypeSerializer |
findPropertyContentTypeSerializer(JavaType containerType,
SerializationConfig config,
AnnotatedMember accessor)
Method called to create a type information serializer for values of given
container property
if one is needed.
|
TypeSerializer |
findPropertyTypeSerializer(JavaType 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.
|
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
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.
|
SerializerFactory |
withConfig(SerializerFactoryConfig config)
Method used by module registration functionality, to attach additional
serializer providers into this serializer factory.
|
_checkMapContentInclusion, _findContentSerializer, _findInclusionWithContent, _findKeySerializer, buildArraySerializer, buildAtomicReferenceSerializer, buildCollectionSerializer, buildCollectionSerializer, buildContainerSerializer, buildEnumSerializer, buildEnumSetSerializer, buildIndexedListSerializer, buildIterableSerializer, buildIteratorSerializer, buildMapEntrySerializer, buildMapSerializer, createKeySerializer, createKeySerializer, createTypeSerializer, findConverter, findConvertingSerializer, findFilterId, findOptionalStdSerializer, findReferenceSerializer, findSerializerByAddonType, findSerializerByAnnotations, findSerializerByLookup, findSerializerByPrimaryType, findSerializerFromAnnotation, getFactoryConfig, isIndexedList, usesStaticTyping, withAdditionalKeySerializers, withAdditionalSerializers, withSerializerModifier
public static final BeanSerializerFactory instance
BasicSerializerFactory
, this factory is stateless, and
thus a single shared global (== singleton) instance can be used
without thread-safety issues.protected BeanSerializerFactory(SerializerFactoryConfig config)
public SerializerFactory withConfig(SerializerFactoryConfig config)
withConfig
in class BasicSerializerFactory
protected Iterable<Serializers> customSerializers()
customSerializers
in class BasicSerializerFactory
public JsonSerializer<Object> createSerializer(SerializerProvider prov, JavaType origType) throws JsonMappingException
Iterable
.
Note: sub-classes may choose to complete replace implementation, if they want to alter priority of serializer lookups.
createSerializer
in class BasicSerializerFactory
prov
- Provider that needs to be used to resolve annotation-provided
serializers (but NOT for others)JsonMappingException
protected JsonSerializer<?> _createSerializer2(SerializerProvider prov, JavaType type, BeanDescription beanDesc, boolean staticTyping) throws JsonMappingException
JsonMappingException
@Deprecated public JsonSerializer<Object> findBeanSerializer(SerializerProvider prov, JavaType type, BeanDescription beanDesc) throws JsonMappingException
JsonMappingException
public JsonSerializer<Object> findBeanOrAddOnSerializer(SerializerProvider prov, JavaType type, BeanDescription beanDesc, boolean staticTyping) throws JsonMappingException
BeanSerializer
for
given class if at least one property is found, OR, if not,
one of add-on types.
NOTE: behavior changed a bit
JsonMappingException
public TypeSerializer findPropertyTypeSerializer(JavaType baseType, SerializationConfig config, AnnotatedMember accessor) throws JsonMappingException
baseType
- Declared type to use as the base type for type information serializerJsonMappingException
public TypeSerializer findPropertyContentTypeSerializer(JavaType containerType, SerializationConfig config, AnnotatedMember accessor) throws JsonMappingException
containerType
- Declared type of the container to use as the base type for type information serializerJsonMappingException
@Deprecated protected JsonSerializer<Object> constructBeanSerializer(SerializerProvider prov, BeanDescription beanDesc) throws JsonMappingException
JsonMappingException
protected JsonSerializer<Object> constructBeanOrAddOnSerializer(SerializerProvider prov, JavaType type, BeanDescription beanDesc, boolean staticTyping) throws JsonMappingException
JsonMappingException
protected ObjectIdWriter constructObjectIdHandler(SerializerProvider prov, BeanDescription beanDesc, List<BeanPropertyWriter> props) throws JsonMappingException
JsonMappingException
protected BeanPropertyWriter constructFilteredBeanWriter(BeanPropertyWriter writer, Class<?>[] inViews)
protected PropertyBuilder constructPropertyBuilder(SerializationConfig config, BeanDescription beanDesc)
protected BeanSerializerBuilder constructBeanSerializerBuilder(BeanDescription beanDesc)
protected boolean isPotentialBeanType(Class<?> type)
Note that usually we shouldn't really be getting these sort of types anyway; but better safe than sorry.
protected List<BeanPropertyWriter> findBeanProperties(SerializerProvider prov, BeanDescription beanDesc, BeanSerializerBuilder builder) throws JsonMappingException
JsonMappingException
protected List<BeanPropertyWriter> filterBeanProperties(SerializationConfig config, BeanDescription beanDesc, List<BeanPropertyWriter> props)
protected List<BeanPropertyWriter> filterUnwantedJDKProperties(SerializationConfig config, BeanDescription beanDesc, List<BeanPropertyWriter> props)
See issue databind-3305 for details.
protected void processViews(SerializationConfig config, BeanSerializerBuilder builder)
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.
protected void removeIgnorableTypes(SerializationConfig config, BeanDescription beanDesc, List<BeanPropertyDefinition> properties)
JsonIgnoreType
annotation but can be supplied by module-provided introspectors too.
Starting with 2.8 there are also "Config overrides" to consider.protected void removeSetterlessGetters(SerializationConfig config, BeanDescription beanDesc, List<BeanPropertyDefinition> properties)
protected List<BeanPropertyWriter> removeOverlappingTypeIds(SerializerProvider prov, BeanDescription beanDesc, BeanSerializerBuilder builder, List<BeanPropertyWriter> props)
protected BeanPropertyWriter _constructWriter(SerializerProvider prov, BeanPropertyDefinition propDef, PropertyBuilder pb, boolean staticTyping, AnnotatedMember accessor) throws JsonMappingException
BeanPropertyWriter
for
given member (field or method).JsonMappingException
protected JsonSerializer<?> _findUnsupportedTypeSerializer(SerializerProvider ctxt, JavaType type, BeanDescription beanDesc) throws JsonMappingException
JsonMappingException
protected boolean _isUnserializableJacksonType(SerializerProvider ctxt, JavaType type)
Copyright © 2008–2022 FasterXML. All rights reserved.