Package org.codehaus.jackson.map.module
Class SimpleSerializers
- java.lang.Object
-
- org.codehaus.jackson.map.Serializers.Base
-
- org.codehaus.jackson.map.module.SimpleSerializers
-
- All Implemented Interfaces:
Serializers
public class SimpleSerializers extends Serializers.Base
Simple implementationSerializers
which allows registration of serializers based on raw (type erased class). It can work well for basic bean and scalar type serializers, but is not a good fit for handling generic types (likeMap
s andCollection
s).Type registrations are assumed to be general; meaning that registration of serializer for a super type will also be used for handling subtypes, unless an exact match is found first. As an example, handler for
CharSequence
would also be used serializingStringBuilder
instances, unless a direct mapping was found.- Since:
- 1.7
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.codehaus.jackson.map.Serializers
Serializers.Base, Serializers.None
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.HashMap<ClassKey,JsonSerializer<?>>
_classMappings
Class-based mappings that are used both for exact and sub-class matches.protected java.util.HashMap<ClassKey,JsonSerializer<?>>
_interfaceMappings
Interface-based matches.
-
Constructor Summary
Constructors Constructor Description SimpleSerializers()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected JsonSerializer<?>
_findInterfaceMapping(java.lang.Class<?> cls, ClassKey key)
<T> void
addSerializer(java.lang.Class<? extends T> type, JsonSerializer<T> ser)
void
addSerializer(JsonSerializer<?> ser)
Method for adding given serializer for type thatJsonSerializer.handledType()
specifies (which MUST return a non-null class; and can NOT beObject
, as a sanity check).JsonSerializer<?>
findArraySerializer(SerializationConfig config, ArrayType type, BeanDescription beanDesc, BeanProperty property, TypeSerializer elementTypeSerializer, JsonSerializer<java.lang.Object> elementValueSerializer)
Method called by serialization framework first time a serializer is needed for specified array type.JsonSerializer<?>
findCollectionLikeSerializer(SerializationConfig config, CollectionLikeType type, BeanDescription beanDesc, BeanProperty property, TypeSerializer elementTypeSerializer, JsonSerializer<java.lang.Object> elementValueSerializer)
JsonSerializer<?>
findCollectionSerializer(SerializationConfig config, CollectionType type, BeanDescription beanDesc, BeanProperty property, TypeSerializer elementTypeSerializer, JsonSerializer<java.lang.Object> elementValueSerializer)
JsonSerializer<?>
findMapLikeSerializer(SerializationConfig config, MapLikeType type, BeanDescription beanDesc, BeanProperty property, JsonSerializer<java.lang.Object> keySerializer, TypeSerializer elementTypeSerializer, JsonSerializer<java.lang.Object> elementValueSerializer)
JsonSerializer<?>
findMapSerializer(SerializationConfig config, MapType type, BeanDescription beanDesc, BeanProperty property, JsonSerializer<java.lang.Object> keySerializer, TypeSerializer elementTypeSerializer, JsonSerializer<java.lang.Object> elementValueSerializer)
JsonSerializer<?>
findSerializer(SerializationConfig config, JavaType type, BeanDescription beanDesc, BeanProperty property)
Method called by serialization framework first time a serializer is needed for specified type, which is not of a container type (for which other methods are called).
-
-
-
Field Detail
-
_classMappings
protected java.util.HashMap<ClassKey,JsonSerializer<?>> _classMappings
Class-based mappings that are used both for exact and sub-class matches.
-
_interfaceMappings
protected java.util.HashMap<ClassKey,JsonSerializer<?>> _interfaceMappings
Interface-based matches.
-
-
Method Detail
-
addSerializer
public void addSerializer(JsonSerializer<?> ser)
Method for adding given serializer for type thatJsonSerializer.handledType()
specifies (which MUST return a non-null class; and can NOT beObject
, as a sanity check). For serializers that do not declare handled type, use the variant that takes two arguments.- Parameters:
ser
-
-
addSerializer
public <T> void addSerializer(java.lang.Class<? extends T> type, JsonSerializer<T> ser)
-
findSerializer
public JsonSerializer<?> findSerializer(SerializationConfig config, JavaType type, BeanDescription beanDesc, BeanProperty property)
Description copied from interface:Serializers
Method called by serialization framework first time a serializer is needed for specified type, which is not of a container type (for which other methods are called).Note: in version 1.7, this method was called to find serializers for all type, including container types.
- Specified by:
findSerializer
in interfaceSerializers
- Overrides:
findSerializer
in classSerializers.Base
- Parameters:
config
- Serialization configuration in usetype
- Fully resolved type of instances to serializebeanDesc
- Additional information about type; will always be of typeBasicBeanDescription
(that is, safe to cast to this more specific type)property
- Property that contains values to serialize- Returns:
- Configured serializer to use for the type; or null if implementation does not recognize or support type
-
findArraySerializer
public JsonSerializer<?> findArraySerializer(SerializationConfig config, ArrayType type, BeanDescription beanDesc, BeanProperty property, TypeSerializer elementTypeSerializer, JsonSerializer<java.lang.Object> elementValueSerializer)
Description copied from interface:Serializers
Method called by serialization framework first time a serializer is needed for specified array type. Implementation should return a serializer instance if it supports specified type; or null if it does not.- Specified by:
findArraySerializer
in interfaceSerializers
- Overrides:
findArraySerializer
in classSerializers.Base
-
findCollectionSerializer
public JsonSerializer<?> findCollectionSerializer(SerializationConfig config, CollectionType type, BeanDescription beanDesc, BeanProperty property, TypeSerializer elementTypeSerializer, JsonSerializer<java.lang.Object> elementValueSerializer)
- Specified by:
findCollectionSerializer
in interfaceSerializers
- Overrides:
findCollectionSerializer
in classSerializers.Base
-
findCollectionLikeSerializer
public JsonSerializer<?> findCollectionLikeSerializer(SerializationConfig config, CollectionLikeType type, BeanDescription beanDesc, BeanProperty property, TypeSerializer elementTypeSerializer, JsonSerializer<java.lang.Object> elementValueSerializer)
- Specified by:
findCollectionLikeSerializer
in interfaceSerializers
- Overrides:
findCollectionLikeSerializer
in classSerializers.Base
-
findMapSerializer
public JsonSerializer<?> findMapSerializer(SerializationConfig config, MapType type, BeanDescription beanDesc, BeanProperty property, JsonSerializer<java.lang.Object> keySerializer, TypeSerializer elementTypeSerializer, JsonSerializer<java.lang.Object> elementValueSerializer)
- Specified by:
findMapSerializer
in interfaceSerializers
- Overrides:
findMapSerializer
in classSerializers.Base
-
findMapLikeSerializer
public JsonSerializer<?> findMapLikeSerializer(SerializationConfig config, MapLikeType type, BeanDescription beanDesc, BeanProperty property, JsonSerializer<java.lang.Object> keySerializer, TypeSerializer elementTypeSerializer, JsonSerializer<java.lang.Object> elementValueSerializer)
- Specified by:
findMapLikeSerializer
in interfaceSerializers
- Overrides:
findMapLikeSerializer
in classSerializers.Base
-
_findInterfaceMapping
protected JsonSerializer<?> _findInterfaceMapping(java.lang.Class<?> cls, ClassKey key)
-
-