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 customazibility 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.


Nested Class Summary
static class BasicSerializerFactory.BooleanSerializer
           
static class BasicSerializerFactory.CalendarSerializer
          For time values we should use timestamp, since that is about the only thing that can be reliably converted between date-based objects and json.
static class BasicSerializerFactory.ClassSerializer
          Also: default bean access will not do much good with Class.class.
static class BasicSerializerFactory.DoubleSerializer
           
static class BasicSerializerFactory.EnumSerializer
           
static class BasicSerializerFactory.FloatSerializer
           
static class BasicSerializerFactory.IntegerSerializer
           
static class BasicSerializerFactory.IntLikeSerializer
          Similar to BasicSerializerFactory.IntegerSerializer, but will not cast to Integer: instead, cast is to Number, and conversion is by calling Number.intValue().
static class BasicSerializerFactory.LongSerializer
           
static class BasicSerializerFactory.NullSerializer
          To allow for special handling for null values (in Objects, Arrays, root-level), handling for nulls is done via serializers too.
static class BasicSerializerFactory.NumberSerializer
          As a fallback, we may need to use this serializer for other types of Numbers (custom types).
static class BasicSerializerFactory.SerializableSerializer
           
static class BasicSerializerFactory.SqlDateSerializer
          Compared to regular BasicSerializerFactory.UtilDateSerializer, we do use String representation here.
static class BasicSerializerFactory.SqlTimeSerializer
           
static class BasicSerializerFactory.StringLikeSerializer<T>
          Deprecated. Use ToStringSerializer instead (stand-along class, more accurate name)
static class BasicSerializerFactory.StringSerializer
          This is the special serializer for regular Strings.
static class BasicSerializerFactory.UtilDateSerializer
          For efficiency, we will serialize Dates as longs, instead of potentially more readable Strings.
 
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
<T> JsonSerializer<T>
createSerializer(Class<T> type, SerializationConfig config)
          Main serializer constructor method.
 JsonSerializer<?> findSerializerByAddonType(Class<?> type)
          Reflection-based serialized find method, which checks if given class implements one of recognized "add-on" interfaces.
 JsonSerializer<?> findSerializerByLookup(Class<?> type)
          Fast lookup-based accessor method, which will only check for type itself, but not consider super-classes or implemented interfaces.
 JsonSerializer<?> findSerializerByPrimaryType(Class<?> type, SerializationConfig config)
          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()
           
 
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.

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

getNullSerializer

public final JsonSerializer<?> getNullSerializer()

findSerializerByLookup

public final JsonSerializer<?> findSerializerByLookup(Class<?> type)
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(Class<?> type,
                                                           SerializationConfig config)
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(Class<?> type)
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.