org.codehaus.jackson.map.ser
Class SerializerCache

java.lang.Object
  extended by org.codehaus.jackson.map.ser.SerializerCache

public final class SerializerCache
extends Object

Simple cache object that allows for doing 2-level lookups: first level is by "local" read-only lookup Map (used without locking) and second backup level is by a shared modifiable HashMap. The idea is that after a while, most serializers are found from the local Map (to optimize performance, reduce lock contention), but that during buildup we can use a shared map to reduce both number of distinct read-only maps constructed, and number of serializers constructed.

Since version 1.5 cache will actually contain three kinds of entries, based on combination of class pair key. First class in key is for the type to serialize, and second one is type used for determining how to resolve value type. One (but not both) of entries can be null.


Nested Class Summary
static class SerializerCache.TypedKeyFull
           
static class SerializerCache.TypedKeyRaw
          Key object used for "typed" serializers (type serializer wrapping value serializer).
static class SerializerCache.UntypedKeyRaw
           
 
Constructor Summary
SerializerCache()
           
 
Method Summary
 void addNonTypedSerializer(Class<?> type, JsonSerializer<Object> ser)
           
 void addNonTypedSerializer(JavaType type, JsonSerializer<Object> ser)
           
 void addTypedSerializer(Class<?> cls, JsonSerializer<Object> ser)
           
 void addTypedSerializer(JavaType type, JsonSerializer<Object> ser)
          Method called if none of lookups succeeded, and caller had to construct a serializer.
 void flush()
           
 ReadOnlyClassToSerializerMap getReadOnlyLookupMap()
          Method that can be called to get a read-only instance populated from the most recent version of the shared lookup Map.
 int size()
           
 JsonSerializer<Object> typedValueSerializer(Class<?> cls)
           
 JsonSerializer<Object> typedValueSerializer(JavaType type)
           
 JsonSerializer<Object> untypedValueSerializer(Class<?> type)
          Method that checks if the shared (and hence, synchronized) lookup Map might have untyped serializer for given type.
 JsonSerializer<Object> untypedValueSerializer(JavaType type)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SerializerCache

public SerializerCache()
Method Detail

getReadOnlyLookupMap

public ReadOnlyClassToSerializerMap getReadOnlyLookupMap()
Method that can be called to get a read-only instance populated from the most recent version of the shared lookup Map.


untypedValueSerializer

public JsonSerializer<Object> untypedValueSerializer(Class<?> type)
Method that checks if the shared (and hence, synchronized) lookup Map might have untyped serializer for given type.


untypedValueSerializer

public JsonSerializer<Object> untypedValueSerializer(JavaType type)
Since:
1.5

typedValueSerializer

public JsonSerializer<Object> typedValueSerializer(JavaType type)

typedValueSerializer

public JsonSerializer<Object> typedValueSerializer(Class<?> cls)

addTypedSerializer

public void addTypedSerializer(JavaType type,
                               JsonSerializer<Object> ser)
Method called if none of lookups succeeded, and caller had to construct a serializer. If so, we will update the shared lookup map so that it can be resolved via it next time.


addTypedSerializer

public void addTypedSerializer(Class<?> cls,
                               JsonSerializer<Object> ser)

addNonTypedSerializer

public void addNonTypedSerializer(Class<?> type,
                                  JsonSerializer<Object> ser)

addNonTypedSerializer

public void addNonTypedSerializer(JavaType type,
                                  JsonSerializer<Object> ser)
Since:
1.5

size

public int size()
Since:
1.4

flush

public void flush()