Package org.codehaus.jackson.map.ser
Class BasicSerializerFactory
java.lang.Object
org.codehaus.jackson.map.SerializerFactory
org.codehaus.jackson.map.ser.BasicSerializerFactory
- Direct Known Subclasses:
BeanSerializerFactory
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
Collection
).
Since all the serializers are eagerly instantiated, and there is no additional introspection or customizability of these types, this factory is essentially stateless.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.codehaus.jackson.map.SerializerFactory
SerializerFactory.Config
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final HashMap
<String, JsonSerializer<?>> protected static final HashMap
<String, JsonSerializer<?>> 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<?>>> Actually it may not make much sense to eagerly instantiate all kinds of serializers: so this Map actually contains class references, not instancesprotected OptionalHandlerFactory
Helper object used to deal with serializers for optional JDK types (like ones omitted from GAE, Android) -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
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 TypeMethodDescriptionprotected JsonSerializer
<?> buildArraySerializer
(SerializationConfig config, ArrayType type, BasicBeanDescription beanDesc, BeanProperty property, boolean staticTyping, TypeSerializer elementTypeSerializer, JsonSerializer<Object> elementValueSerializer) Helper method that handles configuration details when constructing serializers forObject[]
(and subtypes, except for String).protected JsonSerializer
<?> buildCollectionLikeSerializer
(SerializationConfig config, CollectionLikeType type, BasicBeanDescription beanDesc, BeanProperty property, boolean staticTyping, TypeSerializer elementTypeSerializer, JsonSerializer<Object> elementValueSerializer) Helper method that handles configuration details when constructing serializers for Collection and Collection-like types.protected JsonSerializer
<?> buildCollectionSerializer
(SerializationConfig config, CollectionType type, BasicBeanDescription beanDesc, BeanProperty property, boolean staticTyping, TypeSerializer elementTypeSerializer, JsonSerializer<Object> elementValueSerializer) Helper method that handles configuration details when constructing serializers forList
types that support efficient by-index accessbuildContainerSerializer
(SerializationConfig config, JavaType type, BasicBeanDescription beanDesc, BeanProperty property, boolean staticTyping) protected JsonSerializer
<?> buildEnumMapSerializer
(SerializationConfig config, JavaType type, BasicBeanDescription beanDesc, BeanProperty property, boolean staticTyping, TypeSerializer elementTypeSerializer, JsonSerializer<Object> elementValueSerializer) Helper method that handles configuration details when constructing serializers forEnumMap
types.protected JsonSerializer
<?> buildEnumSetSerializer
(SerializationConfig config, JavaType type, BasicBeanDescription beanDesc, BeanProperty property, boolean staticTyping, TypeSerializer elementTypeSerializer, JsonSerializer<Object> elementValueSerializer) protected JsonSerializer
<?> buildIterableSerializer
(SerializationConfig config, JavaType type, BasicBeanDescription beanDesc, BeanProperty property, boolean staticTyping) protected JsonSerializer
<?> buildIteratorSerializer
(SerializationConfig config, JavaType type, BasicBeanDescription beanDesc, BeanProperty property, boolean staticTyping) protected JsonSerializer
<?> buildMapLikeSerializer
(SerializationConfig config, MapLikeType type, BasicBeanDescription beanDesc, BeanProperty property, boolean staticTyping, JsonSerializer<Object> keySerializer, TypeSerializer elementTypeSerializer, JsonSerializer<Object> elementValueSerializer) Helper method that handles configuration details when constructing serializers for all "Map-like" types; both ones that implementMap
and ones that do not (but that have been indicated to behave like Maps).protected JsonSerializer
<?> buildMapSerializer
(SerializationConfig config, MapType type, BasicBeanDescription beanDesc, BeanProperty property, boolean staticTyping, JsonSerializer<Object> keySerializer, TypeSerializer elementTypeSerializer, JsonSerializer<Object> elementValueSerializer) Helper method that handles configuration details when constructing serializers forMap
types.abstract JsonSerializer
<Object> createSerializer
(SerializationConfig config, JavaType type, BeanProperty property) Method called to create (or, for immutable serializers, reuse) a serializer for given type.createTypeSerializer
(SerializationConfig config, JavaType baseType, BeanProperty property) Method called to construct a type serializer for values with given declared base type.protected abstract Iterable
<Serializers> protected static JsonSerializer
<Object> findContentSerializer
(SerializationConfig config, Annotated a, BeanProperty property) protected static JsonSerializer
<Object> findKeySerializer
(SerializationConfig config, Annotated a, BeanProperty property) final JsonSerializer
<?> findSerializerByAddonType
(SerializationConfig config, JavaType javaType, BasicBeanDescription beanDesc, BeanProperty property, boolean staticTyping) Reflection-based serialized find method, which checks if given class implements one of recognized "add-on" interfaces.final JsonSerializer
<?> findSerializerByLookup
(JavaType type, SerializationConfig config, BasicBeanDescription beanDesc, BeanProperty property, boolean staticTyping) Method that will use fast lookup (and identity comparison) methods to see if we know serializer to use for given type.final JsonSerializer
<?> findSerializerByPrimaryType
(JavaType type, SerializationConfig config, BasicBeanDescription beanDesc, BeanProperty property, 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 withfindSerializerByLookup
).protected JsonSerializer
<Object> findSerializerFromAnnotation
(SerializationConfig config, Annotated a, BeanProperty property) Helper method called to check if a class or method has an annotation (@link org.codehaus.jackson.map.ser.JsonSerialize#using) that tells the class to use for serialization.final JsonSerializer
<?> protected boolean
isIndexedList
(Class<?> cls) protected static <T extends JavaType>
TmodifySecondaryTypesByAnnotation
(SerializationConfig config, Annotated a, T type) protected <T extends JavaType>
TmodifyTypeByAnnotation
(SerializationConfig config, Annotated a, T type) Helper method used to encapsulate details of annotation-based type coercionprotected boolean
usesStaticTyping
(SerializationConfig config, BasicBeanDescription beanDesc, TypeSerializer typeSer, BeanProperty property) 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.Methods inherited from class org.codehaus.jackson.map.SerializerFactory
createKeySerializer, createSerializer, createTypeSerializer, getConfig, withAdditionalKeySerializers, withAdditionalSerializers, withConfig, withSerializerModifier
-
Field Details
-
_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. -
_concreteLazy
Actually it may not make much sense to eagerly instantiate all kinds of serializers: so this Map actually contains class references, not instances- Since:
- 1.6
-
_arraySerializers
-
optionalHandlers
Helper object used to deal with serializers for optional JDK types (like ones omitted from GAE, Android)
-
-
Constructor Details
-
BasicSerializerFactory
protected BasicSerializerFactory()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 Details
-
createSerializer
public abstract JsonSerializer<Object> createSerializer(SerializationConfig config, JavaType type, BeanProperty property) throws JsonMappingException Description copied from class:SerializerFactory
Method called to create (or, for immutable serializers, reuse) a serializer for given type.- Specified by:
createSerializer
in classSerializerFactory
- Throws:
JsonMappingException
-
createTypeSerializer
public TypeSerializer createTypeSerializer(SerializationConfig config, JavaType baseType, BeanProperty property) 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.- Specified by:
createTypeSerializer
in classSerializerFactory
- Parameters:
baseType
- Declared type to use as the base type for type information serializer- Returns:
- Type serializer to use for the base type, if one is needed; null if not.
-
getNullSerializer
-
customSerializers
-
findSerializerByLookup
public final JsonSerializer<?> findSerializerByLookup(JavaType type, SerializationConfig config, BasicBeanDescription beanDesc, BeanProperty property, boolean staticTyping) Method that will use fast lookup (and identity comparison) methods to see if we know serializer to use for given type. -
findSerializerByPrimaryType
public final JsonSerializer<?> findSerializerByPrimaryType(JavaType type, SerializationConfig config, BasicBeanDescription beanDesc, BeanProperty property, 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 withfindSerializerByLookup
). This does not include "secondary" interfaces, but mostly concrete or abstract base classes.- Throws:
JsonMappingException
-
findSerializerByAddonType
public final JsonSerializer<?> findSerializerByAddonType(SerializationConfig config, JavaType javaType, BasicBeanDescription beanDesc, BeanProperty property, 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 implementIterable
, but their main function is usually something else. The reason for- Throws:
JsonMappingException
-
findSerializerFromAnnotation
protected JsonSerializer<Object> findSerializerFromAnnotation(SerializationConfig config, Annotated a, BeanProperty property) throws JsonMappingException Helper method called to check if a class or method has an annotation (@link org.codehaus.jackson.map.ser.JsonSerialize#using) that tells the class to use for serialization. Returns null if no such annotation found.- Throws:
JsonMappingException
-
buildContainerSerializer
public JsonSerializer<?> buildContainerSerializer(SerializationConfig config, JavaType type, BasicBeanDescription beanDesc, BeanProperty property, boolean staticTyping) -
buildCollectionLikeSerializer
protected JsonSerializer<?> buildCollectionLikeSerializer(SerializationConfig config, CollectionLikeType type, BasicBeanDescription beanDesc, BeanProperty property, boolean staticTyping, TypeSerializer elementTypeSerializer, JsonSerializer<Object> elementValueSerializer) Helper method that handles configuration details when constructing serializers for Collection and Collection-like types.- Since:
- 1.8
-
buildCollectionSerializer
protected JsonSerializer<?> buildCollectionSerializer(SerializationConfig config, CollectionType type, BasicBeanDescription beanDesc, BeanProperty property, boolean staticTyping, TypeSerializer elementTypeSerializer, JsonSerializer<Object> elementValueSerializer) Helper method that handles configuration details when constructing serializers forList
types that support efficient by-index accessNote: signature changed in 1.8, to take 'staticTyping' argument
-
buildEnumSetSerializer
protected JsonSerializer<?> buildEnumSetSerializer(SerializationConfig config, JavaType type, BasicBeanDescription beanDesc, BeanProperty property, boolean staticTyping, TypeSerializer elementTypeSerializer, JsonSerializer<Object> elementValueSerializer) -
isIndexedList
- Since:
- 1.8
-
buildMapLikeSerializer
protected JsonSerializer<?> buildMapLikeSerializer(SerializationConfig config, MapLikeType type, BasicBeanDescription beanDesc, BeanProperty property, boolean staticTyping, JsonSerializer<Object> keySerializer, TypeSerializer elementTypeSerializer, JsonSerializer<Object> elementValueSerializer) Helper method that handles configuration details when constructing serializers for all "Map-like" types; both ones that implementMap
and ones that do not (but that have been indicated to behave like Maps).- Since:
- 1.8
-
buildMapSerializer
protected JsonSerializer<?> buildMapSerializer(SerializationConfig config, MapType type, BasicBeanDescription beanDesc, BeanProperty property, boolean staticTyping, JsonSerializer<Object> keySerializer, TypeSerializer elementTypeSerializer, JsonSerializer<Object> elementValueSerializer) Helper method that handles configuration details when constructing serializers forMap
types.Note: signature changed in 1.8, to take 'staticTyping' argument
-
buildEnumMapSerializer
protected JsonSerializer<?> buildEnumMapSerializer(SerializationConfig config, JavaType type, BasicBeanDescription beanDesc, BeanProperty property, boolean staticTyping, TypeSerializer elementTypeSerializer, JsonSerializer<Object> elementValueSerializer) Helper method that handles configuration details when constructing serializers forEnumMap
types.Note: signature changed in 1.8, to take 'staticTyping' argument
-
buildArraySerializer
protected JsonSerializer<?> buildArraySerializer(SerializationConfig config, ArrayType type, BasicBeanDescription beanDesc, BeanProperty property, boolean staticTyping, TypeSerializer elementTypeSerializer, JsonSerializer<Object> elementValueSerializer) Helper method that handles configuration details when constructing serializers forObject[]
(and subtypes, except for String). -
buildIteratorSerializer
protected JsonSerializer<?> buildIteratorSerializer(SerializationConfig config, JavaType type, BasicBeanDescription beanDesc, BeanProperty property, boolean staticTyping) -
buildIterableSerializer
protected JsonSerializer<?> buildIterableSerializer(SerializationConfig config, JavaType type, BasicBeanDescription beanDesc, BeanProperty property, boolean staticTyping) -
modifyTypeByAnnotation
protected <T extends JavaType> T modifyTypeByAnnotation(SerializationConfig config, Annotated a, T type) Helper method used to encapsulate details of annotation-based type coercion- Since:
- 1.8
-
modifySecondaryTypesByAnnotation
protected static <T extends JavaType> T modifySecondaryTypesByAnnotation(SerializationConfig config, Annotated a, T type) - Since:
- 1.8
-
findKeySerializer
protected static JsonSerializer<Object> findKeySerializer(SerializationConfig config, Annotated a, BeanProperty property) -
findContentSerializer
protected static JsonSerializer<Object> findContentSerializer(SerializationConfig config, Annotated a, BeanProperty property) -
usesStaticTyping
protected boolean usesStaticTyping(SerializationConfig config, BasicBeanDescription beanDesc, TypeSerializer typeSer, BeanProperty property) 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).
-