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
public abstract class BasicSerializerFactory extends SerializerFactory
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 asCollection
).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
Fields Modifier and Type Field Description protected static java.util.HashMap<java.lang.String,JsonSerializer<?>>
_arraySerializers
protected static java.util.HashMap<java.lang.String,JsonSerializer<?>>
_concrete
Since these are all JDK classes, we shouldn't have to worry about ClassLoader used to load them.protected static java.util.HashMap<java.lang.String,java.lang.Class<? extends JsonSerializer<?>>>
_concreteLazy
Actually it may not make much sense to eagerly instantiate all kinds of serializers: so this Map actually contains class references, not instancesprotected OptionalHandlerFactory
optionalHandlers
Helper object used to deal with serializers for optional JDK types (like ones omitted from GAE, Android)
-
Constructor Summary
Constructors Modifier Constructor Description 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 Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected JsonSerializer<?>
buildArraySerializer(SerializationConfig config, ArrayType type, BasicBeanDescription beanDesc, BeanProperty property, boolean staticTyping, TypeSerializer elementTypeSerializer, JsonSerializer<java.lang.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<java.lang.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<java.lang.Object> elementValueSerializer)
Helper method that handles configuration details when constructing serializers forList
types that support efficient by-index accessJsonSerializer<?>
buildContainerSerializer(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<java.lang.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<java.lang.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<java.lang.Object> keySerializer, TypeSerializer elementTypeSerializer, JsonSerializer<java.lang.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<java.lang.Object> keySerializer, TypeSerializer elementTypeSerializer, JsonSerializer<java.lang.Object> elementValueSerializer)
Helper method that handles configuration details when constructing serializers forMap
types.abstract JsonSerializer<java.lang.Object>
createSerializer(SerializationConfig config, JavaType type, BeanProperty property)
Method called to create (or, for immutable serializers, reuse) a serializer for given type.TypeSerializer
createTypeSerializer(SerializationConfig config, JavaType baseType, BeanProperty property)
Method called to construct a type serializer for values with given declared base type.protected abstract java.lang.Iterable<Serializers>
customSerializers()
protected static JsonSerializer<java.lang.Object>
findContentSerializer(SerializationConfig config, Annotated a, BeanProperty property)
protected static JsonSerializer<java.lang.Object>
findKeySerializer(SerializationConfig config, Annotated a, BeanProperty property)
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.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.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<java.lang.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.JsonSerializer<?>
getNullSerializer()
protected boolean
isIndexedList(java.lang.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 Detail
-
_concrete
protected static final java.util.HashMap<java.lang.String,JsonSerializer<?>> _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
protected static final java.util.HashMap<java.lang.String,java.lang.Class<? extends JsonSerializer<?>>> _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
protected static final java.util.HashMap<java.lang.String,JsonSerializer<?>> _arraySerializers
-
optionalHandlers
protected OptionalHandlerFactory optionalHandlers
Helper object used to deal with serializers for optional JDK types (like ones omitted from GAE, Android)
-
-
Method Detail
-
createSerializer
public abstract JsonSerializer<java.lang.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
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
public final JsonSerializer<?> getNullSerializer()
-
customSerializers
protected abstract java.lang.Iterable<Serializers> 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<java.lang.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<java.lang.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<java.lang.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<java.lang.Object> elementValueSerializer)
-
isIndexedList
protected boolean isIndexedList(java.lang.Class<?> cls)
- Since:
- 1.8
-
buildMapLikeSerializer
protected JsonSerializer<?> buildMapLikeSerializer(SerializationConfig config, MapLikeType type, BasicBeanDescription beanDesc, BeanProperty property, boolean staticTyping, JsonSerializer<java.lang.Object> keySerializer, TypeSerializer elementTypeSerializer, JsonSerializer<java.lang.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<java.lang.Object> keySerializer, TypeSerializer elementTypeSerializer, JsonSerializer<java.lang.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<java.lang.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<java.lang.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<java.lang.Object> findKeySerializer(SerializationConfig config, Annotated a, BeanProperty property)
-
findContentSerializer
protected static JsonSerializer<java.lang.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).
-
-