Top Description Fields Constructors Methods
tools.jackson.databind.ser

public final Class SerializerCache

extends Object
implements Snapshottable<SerializerCache>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, tools.jackson.core.util.Snapshottable
Imports
java.util.concurrent.atomic.AtomicReference, tools.jackson.core.util.Snapshottable, tools.jackson.databind.*, tools.jackson.databind.ser.impl.ReadOnlyClassToSerializerMap, tools.jackson.databind.util.LookupCache, .SimpleLookupCache, .TypeKey

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.

Field Summary

Modifier and TypeField and Description
private final transient AtomicReference<ReadOnlyClassToSerializerMap>
_readOnlyMap

Most recent read-only instance, created from _sharedMap, if any.

private final LookupCache<TypeKey, ValueSerializer<Object>>
_sharedMap

Shared, modifiable map; used if local read-only copy does not contain serializer caller expects.

public static final int
DEFAULT_MAX_CACHE_SIZE

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

private static final long

Constructor Summary

AccessConstructor and Description
public
public
SerializerCache(int maxCached)

public
protected

Method Summary

Modifier and TypeMethod and Description
private final synchronized ReadOnlyClassToSerializerMap
public void
public void
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.

public void
addTypedSerializer(JavaType type, ValueSerializer<Object> ser)

Method called if none of lookups succeeded, and caller had to construct a serializer.

public void
public synchronized void
flush()

Method called by StdSerializationContext#flushCachedSerializers() to clear all cached serializers

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.

protected Object
public int
size()

public SerializerCache
snapshot()

Implements tools.jackson.core.util.Snapshottable.snapshot.

Method to call to get an instance that may not be modified through any other object, including `this`.

public ValueSerializer<Object>
public ValueSerializer<Object>
public ValueSerializer<Object>
untypedValueSerializer(Class<?> type)

Method that checks if the shared (and hence, synchronized) lookup Map might have untyped serializer for given type.

public ValueSerializer<Object>
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_readOnlyMapback to summary
private final transient AtomicReference<ReadOnlyClassToSerializerMap> _readOnlyMap

Most recent read-only instance, created from _sharedMap, if any.

_sharedMapback to summary
private final LookupCache<TypeKey, ValueSerializer<Object>> _sharedMap

Shared, modifiable map; used if local read-only copy does not contain serializer caller expects.

Note

keys are of various types (see below for key types), in addition to basic JavaType used for "untyped" serializers.

DEFAULT_MAX_CACHE_SIZEback to summary
public static final int DEFAULT_MAX_CACHE_SIZE

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

serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

SerializerCacheback to summary
public SerializerCache()
SerializerCacheback to summary
public SerializerCache(int maxCached)
Since
3.0
SerializerCacheback to summary
public SerializerCache(LookupCache<TypeKey, ValueSerializer<Object>> cache)
SerializerCacheback to summary
protected SerializerCache(SimpleLookupCache<TypeKey, ValueSerializer<Object>> shared)

Method Detail

_makeReadOnlyLookupMapback to summary
private final synchronized ReadOnlyClassToSerializerMap _makeReadOnlyLookupMap()
addAndResolveNonTypedSerializerback to summary
public void addAndResolveNonTypedSerializer(Class<?> type, ValueSerializer<Object> ser, SerializationContext provider)
addAndResolveNonTypedSerializerback to summary
public void addAndResolveNonTypedSerializer(JavaType type, ValueSerializer<Object> ser, SerializationContext provider)
addAndResolveNonTypedSerializerback to summary
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.

addTypedSerializerback to summary
public void addTypedSerializer(JavaType type, ValueSerializer<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.

addTypedSerializerback to summary
public void addTypedSerializer(Class<?> cls, ValueSerializer<Object> ser)
flushback to summary
public synchronized void flush()

Method called by StdSerializationContext#flushCachedSerializers() to clear all cached serializers

getReadOnlyLookupMapback to summary
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.

readResolveback to summary
protected Object readResolve()
sizeback to summary
public int size()
snapshotback to summary
public SerializerCache snapshot()

Implements tools.jackson.core.util.Snapshottable.snapshot.

Doc from tools.jackson.core.util.Snapshottable.snapshot.

Method to call to get an instance that may not be modified through any other object, including `this`. That instance may be `this` if (and only if) this instance is effectively immutable (unmodifiable) through its API: if this is not the case, a new copy with same configuration must be created and returned.

Annotations
@Override
typedValueSerializerback to summary
public ValueSerializer<Object> typedValueSerializer(JavaType type)
typedValueSerializerback to summary
public ValueSerializer<Object> typedValueSerializer(Class<?> cls)
untypedValueSerializerback to summary
public ValueSerializer<Object> untypedValueSerializer(Class<?> type)

Method that checks if the shared (and hence, synchronized) lookup Map might have untyped serializer for given type.

untypedValueSerializerback to summary
public ValueSerializer<Object> untypedValueSerializer(JavaType type)