Class SerializerCache
- java.lang.Object
-
- com.fasterxml.jackson.databind.ser.SerializerCache
-
public final class SerializerCache extends java.lang.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.Cache contains 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.
-
-
Constructor Summary
Constructors Constructor Description SerializerCache()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAndResolveNonTypedSerializer(JavaType type, JsonSerializer<java.lang.Object> ser, SerializerProvider provider)
void
addAndResolveNonTypedSerializer(java.lang.Class<?> rawType, JavaType fullType, JsonSerializer<java.lang.Object> ser, SerializerProvider provider)
Another alternative that will cover both access via raw type and matching fully resolved type, in one fell swoop.void
addAndResolveNonTypedSerializer(java.lang.Class<?> type, JsonSerializer<java.lang.Object> ser, SerializerProvider provider)
void
addTypedSerializer(JavaType type, JsonSerializer<java.lang.Object> ser)
Method called if none of lookups succeeded, and caller had to construct a serializer.void
addTypedSerializer(java.lang.Class<?> cls, JsonSerializer<java.lang.Object> ser)
void
flush()
Method called by StdSerializerProvider#flushCachedSerializers() to clear all cached serializersReadOnlyClassToSerializerMap
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<java.lang.Object>
typedValueSerializer(JavaType type)
JsonSerializer<java.lang.Object>
typedValueSerializer(java.lang.Class<?> cls)
JsonSerializer<java.lang.Object>
untypedValueSerializer(JavaType type)
JsonSerializer<java.lang.Object>
untypedValueSerializer(java.lang.Class<?> type)
Method that checks if the shared (and hence, synchronized) lookup Map might have untyped serializer for given type.
-
-
-
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.
-
size
public int size()
-
untypedValueSerializer
public JsonSerializer<java.lang.Object> untypedValueSerializer(java.lang.Class<?> type)
Method that checks if the shared (and hence, synchronized) lookup Map might have untyped serializer for given type.
-
untypedValueSerializer
public JsonSerializer<java.lang.Object> untypedValueSerializer(JavaType type)
-
typedValueSerializer
public JsonSerializer<java.lang.Object> typedValueSerializer(JavaType type)
-
typedValueSerializer
public JsonSerializer<java.lang.Object> typedValueSerializer(java.lang.Class<?> cls)
-
addTypedSerializer
public void addTypedSerializer(JavaType type, JsonSerializer<java.lang.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(java.lang.Class<?> cls, JsonSerializer<java.lang.Object> ser)
-
addAndResolveNonTypedSerializer
public void addAndResolveNonTypedSerializer(java.lang.Class<?> type, JsonSerializer<java.lang.Object> ser, SerializerProvider provider) throws JsonMappingException
- Throws:
JsonMappingException
-
addAndResolveNonTypedSerializer
public void addAndResolveNonTypedSerializer(JavaType type, JsonSerializer<java.lang.Object> ser, SerializerProvider provider) throws JsonMappingException
- Throws:
JsonMappingException
-
addAndResolveNonTypedSerializer
public void addAndResolveNonTypedSerializer(java.lang.Class<?> rawType, JavaType fullType, JsonSerializer<java.lang.Object> ser, SerializerProvider provider) throws JsonMappingException
Another alternative that will cover both access via raw type and matching fully resolved type, in one fell swoop.- Throws:
JsonMappingException
- Since:
- 2.7
-
flush
public void flush()
Method called by StdSerializerProvider#flushCachedSerializers() to clear all cached serializers
-
-