com.fasterxml.jackson.databind.module
Class SimpleSerializers

java.lang.Object
  extended by com.fasterxml.jackson.databind.ser.Serializers.Base
      extended by com.fasterxml.jackson.databind.module.SimpleSerializers
All Implemented Interfaces:
Serializers

public class SimpleSerializers
extends Serializers.Base

Simple implementation 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 Maps and Collections).

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.


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.fasterxml.jackson.databind.ser.Serializers
Serializers.Base
 
Field Summary
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 Summary
SimpleSerializers()
           
 
Method Summary
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, 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, TypeSerializer elementTypeSerializer, JsonSerializer<Object> elementValueSerializer)
          Method called by serialization framework first time a serializer is needed for specified "Collection-like" type (type that acts like Collection, but does not implement it).
 JsonSerializer<?> findCollectionSerializer(SerializationConfig config, CollectionType type, BeanDescription beanDesc, TypeSerializer elementTypeSerializer, JsonSerializer<Object> elementValueSerializer)
          Method called by serialization framework first time a serializer is needed for specified Collection type.
 JsonSerializer<?> findMapLikeSerializer(SerializationConfig config, MapLikeType type, BeanDescription beanDesc, JsonSerializer<Object> keySerializer, TypeSerializer elementTypeSerializer, JsonSerializer<Object> elementValueSerializer)
          Method called by serialization framework first time a serializer is needed for specified "Map-like" type (type that acts like Map, but does not implement it).
 JsonSerializer<?> findMapSerializer(SerializationConfig config, MapType type, BeanDescription beanDesc, JsonSerializer<Object> keySerializer, TypeSerializer elementTypeSerializer, JsonSerializer<Object> elementValueSerializer)
          Method called by serialization framework first time a serializer is needed for specified Map type.
 JsonSerializer<?> findSerializer(SerializationConfig config, JavaType type, BeanDescription beanDesc)
          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).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_classMappings

protected HashMap<ClassKey,JsonSerializer<?>> _classMappings
Class-based mappings that are used both for exact and sub-class matches.


_interfaceMappings

protected HashMap<ClassKey,JsonSerializer<?>> _interfaceMappings
Interface-based matches.

Constructor Detail

SimpleSerializers

public SimpleSerializers()
Method Detail

addSerializer

public 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). For serializers that do not declare handled type, use the variant that takes two arguments.

Parameters:
ser -

addSerializer

public <T> void addSerializer(Class<? extends T> type,
                              JsonSerializer<T> ser)

findSerializer

public JsonSerializer<?> findSerializer(SerializationConfig config,
                                        JavaType type,
                                        BeanDescription beanDesc)
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).

Specified by:
findSerializer in interface Serializers
Overrides:
findSerializer in class Serializers.Base
Parameters:
config - Serialization configuration in use
type - Fully resolved type of instances to serialize
beanDesc - Additional information about type
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,
                                             TypeSerializer elementTypeSerializer,
                                             JsonSerializer<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 interface Serializers
Overrides:
findArraySerializer in class Serializers.Base

findCollectionSerializer

public JsonSerializer<?> findCollectionSerializer(SerializationConfig config,
                                                  CollectionType type,
                                                  BeanDescription beanDesc,
                                                  TypeSerializer elementTypeSerializer,
                                                  JsonSerializer<Object> elementValueSerializer)
Description copied from interface: Serializers
Method called by serialization framework first time a serializer is needed for specified Collection type. Implementation should return a serializer instance if it supports specified type; or null if it does not.

Specified by:
findCollectionSerializer in interface Serializers
Overrides:
findCollectionSerializer in class Serializers.Base

findCollectionLikeSerializer

public JsonSerializer<?> findCollectionLikeSerializer(SerializationConfig config,
                                                      CollectionLikeType type,
                                                      BeanDescription beanDesc,
                                                      TypeSerializer elementTypeSerializer,
                                                      JsonSerializer<Object> elementValueSerializer)
Description copied from interface: Serializers
Method called by serialization framework first time a serializer is needed for specified "Collection-like" type (type that acts like Collection, but does not implement it). Implementation should return a serializer instance if it supports specified type; or null if it does not.

Specified by:
findCollectionLikeSerializer in interface Serializers
Overrides:
findCollectionLikeSerializer in class Serializers.Base

findMapSerializer

public JsonSerializer<?> findMapSerializer(SerializationConfig config,
                                           MapType type,
                                           BeanDescription beanDesc,
                                           JsonSerializer<Object> keySerializer,
                                           TypeSerializer elementTypeSerializer,
                                           JsonSerializer<Object> elementValueSerializer)
Description copied from interface: Serializers
Method called by serialization framework first time a serializer is needed for specified Map type. Implementation should return a serializer instance if it supports specified type; or null if it does not.

Specified by:
findMapSerializer in interface Serializers
Overrides:
findMapSerializer in class Serializers.Base

findMapLikeSerializer

public JsonSerializer<?> findMapLikeSerializer(SerializationConfig config,
                                               MapLikeType type,
                                               BeanDescription beanDesc,
                                               JsonSerializer<Object> keySerializer,
                                               TypeSerializer elementTypeSerializer,
                                               JsonSerializer<Object> elementValueSerializer)
Description copied from interface: Serializers
Method called by serialization framework first time a serializer is needed for specified "Map-like" type (type that acts like Map, but does not implement it). Implementation should return a serializer instance if it supports specified type; or null if it does not.

Specified by:
findMapLikeSerializer in interface Serializers
Overrides:
findMapLikeSerializer in class Serializers.Base

_findInterfaceMapping

protected JsonSerializer<?> _findInterfaceMapping(Class<?> cls,
                                                  ClassKey key)


Copyright © 2012 fasterxml.com. All Rights Reserved.