public class SimpleSerializers extends Serializers.Base
Serializers
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 (like Map
s and Collection
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
serializing StringBuilder
instances, unless a direct mapping was found.
Serializers.Base, Serializers.None
Modifier and Type | Field and Description |
---|---|
protected HashMap<ClassKey,JsonSerializer<?>> |
_classMappings
Class-based mappings that are used both for exact and
sub-class matches.
|
protected HashMap<ClassKey,JsonSerializer<?>> |
_interfaceMappings
Interface-based matches.
|
Constructor and Description |
---|
SimpleSerializers() |
Modifier and Type | Method and Description |
---|---|
protected JsonSerializer<?> |
_findInterfaceMapping(Class<?> cls,
ClassKey key) |
<T> void |
addSerializer(Class<? extends T> type,
JsonSerializer<T> ser) |
void |
addSerializer(JsonSerializer<?> ser)
Method for adding given serializer for type that
JsonSerializer.handledType()
specifies (which MUST return a non-null class; and can NOT be Object , as a
sanity check). |
JsonSerializer<?> |
findArraySerializer(SerializationConfig config,
ArrayType type,
BeanDescription beanDesc,
BeanProperty property,
TypeSerializer elementTypeSerializer,
JsonSerializer<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<Object> elementValueSerializer) |
JsonSerializer<?> |
findCollectionSerializer(SerializationConfig config,
CollectionType type,
BeanDescription beanDesc,
BeanProperty property,
TypeSerializer elementTypeSerializer,
JsonSerializer<Object> elementValueSerializer) |
JsonSerializer<?> |
findMapLikeSerializer(SerializationConfig config,
MapLikeType type,
BeanDescription beanDesc,
BeanProperty property,
JsonSerializer<Object> keySerializer,
TypeSerializer elementTypeSerializer,
JsonSerializer<Object> elementValueSerializer) |
JsonSerializer<?> |
findMapSerializer(SerializationConfig config,
MapType type,
BeanDescription beanDesc,
BeanProperty property,
JsonSerializer<Object> keySerializer,
TypeSerializer elementTypeSerializer,
JsonSerializer<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).
|
protected HashMap<ClassKey,JsonSerializer<?>> _classMappings
protected HashMap<ClassKey,JsonSerializer<?>> _interfaceMappings
public void addSerializer(JsonSerializer<?> ser)
JsonSerializer.handledType()
specifies (which MUST return a non-null class; and can NOT be Object
, as a
sanity check).
For serializers that do not declare handled type, use the variant that takes
two arguments.ser
- public <T> void addSerializer(Class<? extends T> type, JsonSerializer<T> ser)
public JsonSerializer<?> findSerializer(SerializationConfig config, JavaType type, BeanDescription beanDesc, BeanProperty property)
Serializers
Note: in version 1.7, this method was called to find serializers for all type, including container types.
findSerializer
in interface Serializers
findSerializer
in class Serializers.Base
config
- Serialization configuration in usetype
- Fully resolved type of instances to serializebeanDesc
- Additional information about type; will always be of type
BasicBeanDescription
(that is,
safe to cast to this more specific type)property
- Property that contains values to serializepublic JsonSerializer<?> findArraySerializer(SerializationConfig config, ArrayType type, BeanDescription beanDesc, BeanProperty property, TypeSerializer elementTypeSerializer, JsonSerializer<Object> elementValueSerializer)
Serializers
findArraySerializer
in interface Serializers
findArraySerializer
in class Serializers.Base
public JsonSerializer<?> findCollectionSerializer(SerializationConfig config, CollectionType type, BeanDescription beanDesc, BeanProperty property, TypeSerializer elementTypeSerializer, JsonSerializer<Object> elementValueSerializer)
findCollectionSerializer
in interface Serializers
findCollectionSerializer
in class Serializers.Base
public JsonSerializer<?> findCollectionLikeSerializer(SerializationConfig config, CollectionLikeType type, BeanDescription beanDesc, BeanProperty property, TypeSerializer elementTypeSerializer, JsonSerializer<Object> elementValueSerializer)
findCollectionLikeSerializer
in interface Serializers
findCollectionLikeSerializer
in class Serializers.Base
public JsonSerializer<?> findMapSerializer(SerializationConfig config, MapType type, BeanDescription beanDesc, BeanProperty property, JsonSerializer<Object> keySerializer, TypeSerializer elementTypeSerializer, JsonSerializer<Object> elementValueSerializer)
findMapSerializer
in interface Serializers
findMapSerializer
in class Serializers.Base
public JsonSerializer<?> findMapLikeSerializer(SerializationConfig config, MapLikeType type, BeanDescription beanDesc, BeanProperty property, JsonSerializer<Object> keySerializer, TypeSerializer elementTypeSerializer, JsonSerializer<Object> elementValueSerializer)
findMapLikeSerializer
in interface Serializers
findMapLikeSerializer
in class Serializers.Base
protected JsonSerializer<?> _findInterfaceMapping(Class<?> cls, ClassKey key)