java.lang.Object
tools.jackson.databind.ser.SerializerCache
- All Implemented Interfaces:
Serializable
,tools.jackson.core.util.Snapshottable<SerializerCache>
public final class SerializerCache
extends Object
implements tools.jackson.core.util.Snapshottable<SerializerCache>, Serializable
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.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
By default, allow caching of up to 4000 serializer entries (for possibly up to 1000 types; but depending access patterns may be as few as half of that). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAndResolveNonTypedSerializer
(Class<?> rawType, JavaType fullType, ValueSerializer<Object> ser, SerializationContext provider) Another alternative that will cover both access via raw type and matching fully resolved type, in one fell swoop.void
addAndResolveNonTypedSerializer
(Class<?> type, ValueSerializer<Object> ser, SerializationContext provider) void
addAndResolveNonTypedSerializer
(JavaType type, ValueSerializer<Object> ser, SerializationContext provider) void
addTypedSerializer
(Class<?> cls, ValueSerializer<Object> ser) void
addTypedSerializer
(JavaType type, ValueSerializer<Object> ser) Method called if none of lookups succeeded, and caller had to construct a serializer.void
flush()
Method called by StdSerializationContext#flushCachedSerializers() to clear all cached serializersMethod that can be called to get a read-only instance populated from the most recent version of the shared lookup Map.protected Object
int
size()
snapshot()
typedValueSerializer
(Class<?> cls) typedValueSerializer
(JavaType type) untypedValueSerializer
(Class<?> type) Method that checks if the shared (and hence, synchronized) lookup Map might have untyped serializer for given type.
-
Field Details
-
DEFAULT_MAX_CACHE_SIZE
public static final int DEFAULT_MAX_CACHE_SIZEBy default, allow caching of up to 4000 serializer entries (for possibly up to 1000 types; but depending access patterns may be as few as half of that).- See Also:
-
-
Constructor Details
-
SerializerCache
public SerializerCache() -
SerializerCache
public SerializerCache(int maxCached) - Since:
- 3.0
-
SerializerCache
-
SerializerCache
-
-
Method Details
-
readResolve
-
snapshot
- Specified by:
snapshot
in interfacetools.jackson.core.util.Snapshottable<SerializerCache>
-
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
Method that checks if the shared (and hence, synchronized) lookup Map might have untyped serializer for given type. -
untypedValueSerializer
-
typedValueSerializer
-
typedValueSerializer
-
addTypedSerializer
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
-
addAndResolveNonTypedSerializer
public void addAndResolveNonTypedSerializer(Class<?> type, ValueSerializer<Object> ser, SerializationContext provider) -
addAndResolveNonTypedSerializer
public void addAndResolveNonTypedSerializer(JavaType type, ValueSerializer<Object> ser, SerializationContext provider) -
addAndResolveNonTypedSerializer
public void addAndResolveNonTypedSerializer(Class<?> rawType, JavaType fullType, ValueSerializer<Object> ser, SerializationContext provider) Another alternative that will cover both access via raw type and matching fully resolved type, in one fell swoop. -
flush
public void flush()Method called by StdSerializationContext#flushCachedSerializers() to clear all cached serializers
-