public class BeanSerializerFactory extends BasicSerializerFactory
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.
Notes for version 1.7 (and above): the new module registration system
required addition of withConfig(org.codehaus.jackson.map.SerializerFactory.Config)
, which has to
be redefined by sub-classes so that they can work properly with
pluggable additional serializer providing components.
Modifier and Type | Class and Description |
---|---|
static class |
BeanSerializerFactory.ConfigImpl
Configuration settings container class for bean serializer factory
|
SerializerFactory.Config
Modifier and Type | Field and Description |
---|---|
protected SerializerFactory.Config |
_factoryConfig
Configuration settings for this factory; immutable instance (just like this
factory), new version created via copy-constructor (fluent-style)
|
static BeanSerializerFactory |
instance
Like
BasicSerializerFactory , this factory is stateless, and
thus a single shared global (== singleton) instance can be used
without thread-safety issues. |
_arraySerializers, _concrete, _concreteLazy, optionalHandlers
Modifier | Constructor and Description |
---|---|
protected |
BeanSerializerFactory(SerializerFactory.Config config)
Constructor for creating instances with specified configuration.
|
Modifier and Type | Method and Description |
---|---|
protected BeanPropertyWriter |
_constructWriter(SerializationConfig config,
TypeBindings typeContext,
PropertyBuilder pb,
boolean staticTyping,
String name,
AnnotatedMember accessor)
Secondary helper method for constructing
BeanPropertyWriter for
given member (field or method). |
protected JsonSerializer<Object> |
constructBeanSerializer(SerializationConfig config,
BasicBeanDescription beanDesc,
BeanProperty property)
Method called to construct serializer for serializing specified bean type.
|
protected BeanSerializerBuilder |
constructBeanSerializerBuilder(BasicBeanDescription beanDesc) |
protected BeanPropertyWriter |
constructFilteredBeanWriter(BeanPropertyWriter writer,
Class<?>[] inViews)
Method called to construct a filtered writer, for given view
definitions.
|
protected PropertyBuilder |
constructPropertyBuilder(SerializationConfig config,
BasicBeanDescription beanDesc) |
JsonSerializer<Object> |
createKeySerializer(SerializationConfig config,
JavaType type,
BeanProperty property)
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) |
JsonSerializer<Object> |
createSerializer(SerializationConfig config,
JavaType origType,
BeanProperty property)
Main serializer constructor method.
|
protected Iterable<Serializers> |
customSerializers() |
protected List<BeanPropertyWriter> |
filterBeanProperties(SerializationConfig config,
BasicBeanDescription beanDesc,
List<BeanPropertyWriter> props)
Overridable method that can filter out properties.
|
protected List<BeanPropertyWriter> |
findBeanProperties(SerializationConfig config,
BasicBeanDescription beanDesc)
Method used to collect all actual serializable properties.
|
JsonSerializer<Object> |
findBeanSerializer(SerializationConfig config,
JavaType type,
BasicBeanDescription beanDesc,
BeanProperty property)
Method that will try to construct a
BeanSerializer for
given class. |
protected Object |
findFilterId(SerializationConfig config,
BasicBeanDescription beanDesc)
Method called to find filter that is configured to be used with bean
serializer being built, if any.
|
TypeSerializer |
findPropertyContentTypeSerializer(JavaType containerType,
SerializationConfig config,
AnnotatedMember accessor,
BeanProperty property)
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,
BeanProperty property)
Method called to create a type information serializer for values of given
non-container property
if one is needed.
|
SerializerFactory.Config |
getConfig() |
protected boolean |
isPotentialBeanType(Class<?> type)
Helper method used to skip processing for types that we know
can not 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,
BasicBeanDescription 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 void |
removeSetterlessGetters(SerializationConfig config,
BasicBeanDescription beanDesc,
List<BeanPropertyDefinition> properties)
Helper method that will remove all properties that do not have a
mutator.
|
protected List<BeanPropertyWriter> |
sortBeanProperties(SerializationConfig config,
BasicBeanDescription beanDesc,
List<BeanPropertyWriter> props)
Deprecated.
Since 1.9 this method does nothing, so there is no
benefit from overriding it; it will be removed from 2.0.
|
SerializerFactory |
withConfig(SerializerFactory.Config config)
Method used by module registration functionality, to attach additional
serializer providers into this serializer factory.
|
buildArraySerializer, buildCollectionLikeSerializer, buildCollectionSerializer, buildContainerSerializer, buildEnumMapSerializer, buildEnumSetSerializer, buildIterableSerializer, buildIteratorSerializer, buildMapLikeSerializer, buildMapSerializer, createTypeSerializer, findContentSerializer, findKeySerializer, findSerializerByAddonType, findSerializerByLookup, findSerializerByPrimaryType, findSerializerFromAnnotation, getNullSerializer, isIndexedList, modifySecondaryTypesByAnnotation, modifyTypeByAnnotation, usesStaticTyping
createSerializer, createTypeSerializer, 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 final SerializerFactory.Config _factoryConfig
protected BeanSerializerFactory(SerializerFactory.Config config)
public SerializerFactory.Config getConfig()
getConfig
in class SerializerFactory
public SerializerFactory withConfig(SerializerFactory.Config config)
withConfig
in class SerializerFactory
protected Iterable<Serializers> customSerializers()
customSerializers
in class BasicSerializerFactory
public JsonSerializer<Object> createSerializer(SerializationConfig config, JavaType origType, BeanProperty property) 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
JsonMappingException
public JsonSerializer<Object> createKeySerializer(SerializationConfig config, JavaType type, BeanProperty property)
SerializerFactory
JsonToken.FIELD_NAME
) for Map that has specified declared
key type, and is for specified property (or, if property is null, as root value)createKeySerializer
in class SerializerFactory
config
- Serialization configuration in usetype
- Declared type for Map keysproperty
- Property that contains Map being serialized; null when serializing root Map value.public JsonSerializer<Object> findBeanSerializer(SerializationConfig config, JavaType type, BasicBeanDescription beanDesc, BeanProperty property) throws JsonMappingException
BeanSerializer
for
given class. Returns null if no properties are found.JsonMappingException
public TypeSerializer findPropertyTypeSerializer(JavaType baseType, SerializationConfig config, AnnotatedMember accessor, BeanProperty property) throws JsonMappingException
baseType
- Declared type to use as the base type for type information serializerJsonMappingException
public TypeSerializer findPropertyContentTypeSerializer(JavaType containerType, SerializationConfig config, AnnotatedMember accessor, BeanProperty property) throws JsonMappingException
containerType
- Declared type of the container to use as the base type for type information serializerJsonMappingException
protected JsonSerializer<Object> constructBeanSerializer(SerializationConfig config, BasicBeanDescription beanDesc, BeanProperty property) throws JsonMappingException
JsonMappingException
protected BeanPropertyWriter constructFilteredBeanWriter(BeanPropertyWriter writer, Class<?>[] inViews)
protected PropertyBuilder constructPropertyBuilder(SerializationConfig config, BasicBeanDescription beanDesc)
protected BeanSerializerBuilder constructBeanSerializerBuilder(BasicBeanDescription beanDesc)
protected Object findFilterId(SerializationConfig config, BasicBeanDescription 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(SerializationConfig config, BasicBeanDescription beanDesc) throws JsonMappingException
JsonMappingException
protected List<BeanPropertyWriter> filterBeanProperties(SerializationConfig config, BasicBeanDescription beanDesc, List<BeanPropertyWriter> props)
@Deprecated protected List<BeanPropertyWriter> sortBeanProperties(SerializationConfig config, BasicBeanDescription beanDesc, List<BeanPropertyWriter> props)
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.
NOTE: signature of this method changed in 1.7, due to other significant changes (esp. use of builder for serializer construction).
protected void removeIgnorableTypes(SerializationConfig config, BasicBeanDescription beanDesc, List<BeanPropertyDefinition> properties)
JsonIgnoreType
annotation but
can be supplied by module-provided introspectors too.protected void removeSetterlessGetters(SerializationConfig config, BasicBeanDescription beanDesc, List<BeanPropertyDefinition> properties)
protected BeanPropertyWriter _constructWriter(SerializationConfig config, TypeBindings typeContext, PropertyBuilder pb, boolean staticTyping, String name, AnnotatedMember accessor) throws JsonMappingException
BeanPropertyWriter
for
given member (field or method).JsonMappingException