org.codehaus.jackson.map.ser
Class BasicSerializerFactory

java.lang.Object
  extended by org.codehaus.jackson.map.SerializerFactory
      extended by org.codehaus.jackson.map.ser.BasicSerializerFactory
Direct Known Subclasses:
BeanSerializerFactory

public 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 as Collection).

Since all the serializers are eagerly instantiated, and there is no additional introspection or customizability of these types, this factory is stateless. This means that other delegating factories (or SerializerProviders) can just use the shared singleton instance via static instance field.


Field Summary
static BasicSerializerFactory instance
          Stateless global singleton instance that should be used for factories that want to use delegation to access standard serializers.
 
Constructor Summary
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
protected  JsonSerializer<?> buildCollectionSerializer(JavaType type, SerializationConfig config, BasicBeanDescription beanDesc)
           
protected  JsonSerializer<?> buildEnumMapSerializer(JavaType type, SerializationConfig config, BasicBeanDescription beanDesc)
           
protected  JsonSerializer<?> buildEnumSetSerializer(JavaType type, SerializationConfig config, BasicBeanDescription beanDesc)
           
protected  JsonSerializer<?> buildIndexedListSerializer(JavaType type, SerializationConfig config, BasicBeanDescription beanDesc)
           
protected  JsonSerializer<?> buildIterableSerializer(JavaType type, SerializationConfig config, BasicBeanDescription beanDesc)
           
protected  JsonSerializer<?> buildIteratorSerializer(JavaType type, SerializationConfig config, BasicBeanDescription beanDesc)
           
protected  JsonSerializer<?> buildMapSerializer(JavaType type, SerializationConfig config, BasicBeanDescription beanDesc)
          Helper method that handles configuration details when constructing serializers for Map types.
protected  JsonSerializer<?> buildObjectArraySerializer(JavaType type, SerializationConfig config, BasicBeanDescription beanDesc)
          Helper method that handles configuration details when constructing serializers for Object[] (and subtypes).
<T> JsonSerializer<T>
createSerializer(Class<T> type, SerializationConfig config)
          Main serializer constructor method.
 JsonSerializer<Object> createSerializer(JavaType type, SerializationConfig config)
          Method called to create (or, for immutable serializers, reuse) a serializer for given type.
 TypeSerializer createTypeSerializer(JavaType baseType, SerializationConfig config)
          Method called to construct a type serializer for values with given declared base type.
 JsonSerializer<?> findSerializerByAddonType(JavaType javaType, SerializationConfig config, BasicBeanDescription beanDesc)
          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)
          Fast lookup-based accessor method, which will only check for type itself, but not consider super-classes or implemented interfaces.
 JsonSerializer<?> findSerializerByPrimaryType(JavaType type, SerializationConfig config, BasicBeanDescription beanDesc)
          Reflection-based serialized find method, which checks if given class is a sub-type of one of well-known classes, or implements a "primary" interface.
protected  JsonSerializer<Object> findSerializerFromAnnotation(SerializationConfig config, Annotated a)
          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 usesStaticTyping(SerializationConfig config, BasicBeanDescription beanDesc, TypeSerializer typeSer)
          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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

instance

public static final BasicSerializerFactory instance
Stateless global singleton instance that should be used for factories that want to use delegation to access standard serializers.

Constructor Detail

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 Detail

createSerializer

public <T> JsonSerializer<T> createSerializer(Class<T> type,
                                              SerializationConfig config)
Main serializer constructor method. The base implementation within this class first calls a fast lookup method that can find serializers for well-known JDK classes; and if that fails, a slower one that tries to check out which interfaces given Class implements. Sub-classes can (and do) change this behavior to alter behavior.

Overrides:
createSerializer in class SerializerFactory
Parameters:
type - Type to be serialized
config - Generic serialization configuration

createSerializer

public JsonSerializer<Object> createSerializer(JavaType type,
                                               SerializationConfig config)
Description copied from class: SerializerFactory
Method called to create (or, for immutable serializers, reuse) a serializer for given type.

Default implementation just calls SerializerFactory.createSerializer(Class, SerializationConfig); sub-classes need to override method

Overrides:
createSerializer in class SerializerFactory
Parameters:
type - Type to be serialized
config - Generic serialization configuration

createTypeSerializer

public TypeSerializer createTypeSerializer(JavaType baseType,
                                           SerializationConfig config)
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.

Overrides:
createTypeSerializer in class SerializerFactory
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

public final JsonSerializer<?> getNullSerializer()

findSerializerByLookup

public final JsonSerializer<?> findSerializerByLookup(JavaType type,
                                                      SerializationConfig config,
                                                      BasicBeanDescription beanDesc)
Fast lookup-based accessor method, which will only check for type itself, but not consider super-classes or implemented interfaces.


findSerializerByPrimaryType

public final JsonSerializer<?> findSerializerByPrimaryType(JavaType type,
                                                           SerializationConfig config,
                                                           BasicBeanDescription beanDesc)
Reflection-based serialized find method, which checks if given class is a sub-type of one of well-known classes, or implements a "primary" interface. Primary here is defined as the main function of the Object; as opposed to "add-on" functionality.


findSerializerByAddonType

public final JsonSerializer<?> findSerializerByAddonType(JavaType javaType,
                                                         SerializationConfig config,
                                                         BasicBeanDescription beanDesc)
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 implement Iterable, but their main function is usually something else. The reason for


findSerializerFromAnnotation

protected JsonSerializer<Object> findSerializerFromAnnotation(SerializationConfig config,
                                                              Annotated a)
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.


buildMapSerializer

protected JsonSerializer<?> buildMapSerializer(JavaType type,
                                               SerializationConfig config,
                                               BasicBeanDescription beanDesc)
Helper method that handles configuration details when constructing serializers for Map types.


buildEnumMapSerializer

protected JsonSerializer<?> buildEnumMapSerializer(JavaType type,
                                                   SerializationConfig config,
                                                   BasicBeanDescription beanDesc)

buildObjectArraySerializer

protected JsonSerializer<?> buildObjectArraySerializer(JavaType type,
                                                       SerializationConfig config,
                                                       BasicBeanDescription beanDesc)
Helper method that handles configuration details when constructing serializers for Object[] (and subtypes).


buildIndexedListSerializer

protected JsonSerializer<?> buildIndexedListSerializer(JavaType type,
                                                       SerializationConfig config,
                                                       BasicBeanDescription beanDesc)

buildCollectionSerializer

protected JsonSerializer<?> buildCollectionSerializer(JavaType type,
                                                      SerializationConfig config,
                                                      BasicBeanDescription beanDesc)

buildIteratorSerializer

protected JsonSerializer<?> buildIteratorSerializer(JavaType type,
                                                    SerializationConfig config,
                                                    BasicBeanDescription beanDesc)

buildIterableSerializer

protected JsonSerializer<?> buildIterableSerializer(JavaType type,
                                                    SerializationConfig config,
                                                    BasicBeanDescription beanDesc)

buildEnumSetSerializer

protected JsonSerializer<?> buildEnumSetSerializer(JavaType type,
                                                   SerializationConfig config,
                                                   BasicBeanDescription beanDesc)

usesStaticTyping

protected boolean usesStaticTyping(SerializationConfig config,
                                   BasicBeanDescription beanDesc,
                                   TypeSerializer typeSer)
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).