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

public final Class DeserializerCache

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.util.HashMap, .Objects, java.util.concurrent.locks.ReentrantLock, com.fasterxml.jackson.annotation.JsonFormat, tools.jackson.databind.*, tools.jackson.databind.cfg.MapperConfig, tools.jackson.databind.deser.std.StdConvertingDeserializer, tools.jackson.databind.introspect.Annotated, tools.jackson.databind.type.*, tools.jackson.databind.util.ClassUtil, .Converter, .LookupCache, .SimpleLookupCache

Class that defines caching layer between callers (like ObjectMapper, tools.jackson.databind.DeserializationContext) and classes that construct deserializers (tools.jackson.databind.deser.DeserializerFactory).

Field Summary

Modifier and TypeField and Description
private final LookupCache<JavaType, ValueDeserializer<Object>>
_cachedDeserializers

We will also cache some dynamically constructed deserializers; specifically, ones that are expensive to construct.

private final transient HashMap<JavaType, ValueDeserializer<Object>>
_incompleteDeserializers

During deserializer construction process we may need to keep track of partially completed deserializers, to resolve cyclic dependencies.

private final ReentrantLock
_incompleteDeserializersLock

We hold an explicit lock while creating deserializers to avoid creating duplicates.

public static final int
DEFAULT_MAX_CACHE_SIZE

Default size of the underlying cache to use.

private static final long

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

Modifier and TypeMethod and Description
protected ValueDeserializer<Object>
_createAndCache2(DeserializationContext ctxt, DeserializerFactory factory, JavaType type, boolean isCustom)

Method that handles actual construction (via factory) and caching (both intermediate and eventual)

protected ValueDeserializer<Object>
_createAndCacheValueDeserializer(DeserializationContext
Currently active deserialization context
ctxt
,
DeserializerFactory factory, JavaType
Type of property to deserialize (never null, callers verify)
type
)

Method that will try to create a deserializer for given type, and resolve and cache it if necessary

protected ValueDeserializer<Object>
_createDeserializer(DeserializationContext ctxt, DeserializerFactory factory, JavaType type)

Method that does the heavy lifting of checking for per-type annotations, find out full type, and figure out which actual factory method to call.

protected ValueDeserializer<?>
protected ValueDeserializer<Object>
protected KeyDeserializer
protected ValueDeserializer<Object>
private boolean
_hasCustomHandlers(JavaType t)

Helper method used to prevent both caching and cache lookups for structured types that have custom value handlers

private Class<?>
_verifyAsClass(Object src, String methodName, Class<?> noneClass)

public int
cachedDeserializersCount()

Method that can be used to determine how many deserializers this provider is caching currently (if it does caching: default implementation does) Exact count depends on what kind of deserializers get cached; default implementation caches only dynamically constructed deserializers, but not eagerly constructed standard deserializers (which is different from how serializer provider works).

public DeserializerCache
protected Converter<Object, Object>
protected ValueDeserializer<Object>
findConvertingDeserializer(DeserializationContext ctxt, Annotated a, ValueDeserializer<Object> deser)

Helper method that will check whether given annotated entity (usually class, but may also be a property accessor) indicates that a Converter is to be used; and if so, to construct and return suitable serializer for it.

protected ValueDeserializer<Object>
findDeserializerFromAnnotation(DeserializationContext ctxt, Annotated ann)

Helper method called to check if a class or method has annotation that tells which class to use for deserialization.

public KeyDeserializer
findKeyDeserializer(DeserializationContext ctxt, DeserializerFactory factory, JavaType type)

Method called to get hold of a deserializer to use for deserializing keys for java.util.Map.

public ValueDeserializer<Object>
findValueDeserializer(DeserializationContext
Deserialization context
ctxt
,
DeserializerFactory factory, JavaType
Declared type of the value to deserializer (obtained using 'setter' method signature and/or type annotations
propertyType
)

Method called to get hold of a deserializer for a value of given type; or if no such deserializer can be found, a default handler (which may do a best-effort generic serialization or just simply throw an exception when invoked).

public void
flushCachedDeserializers()

Method that will drop all dynamically constructed deserializers (ones that are counted as result value for cachedDeserializersCount).

private JavaType

Returns:

Original type if no annotations are present; or a more specific type derived from it if type annotation(s) was found
modifyTypeByAnnotation
(DeserializationContext ctxt, Annotated
Method or field that the type is associated with
a
,
JavaType
Type derived from the setter argument
type
)

Method called to see if given method has annotations that indicate a more specific type than what the argument specifies.

protected Object
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_cachedDeserializersback to summary
private final LookupCache<JavaType, ValueDeserializer<Object>> _cachedDeserializers

We will also cache some dynamically constructed deserializers; specifically, ones that are expensive to construct. This currently (3.0) means POJO, Enum and Container (collection, map) deserializers.

_incompleteDeserializersback to summary
private final transient HashMap<JavaType, ValueDeserializer<Object>> _incompleteDeserializers

During deserializer construction process we may need to keep track of partially completed deserializers, to resolve cyclic dependencies. This is the map used for storing deserializers before they are fully complete.

_incompleteDeserializersLockback to summary
private final ReentrantLock _incompleteDeserializersLock

We hold an explicit lock while creating deserializers to avoid creating duplicates. Guards _incompleteDeserializers.

DEFAULT_MAX_CACHE_SIZEback to summary
public static final int DEFAULT_MAX_CACHE_SIZE

Default size of the underlying cache to use.

Note

reduced from 2.x default.

serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

DeserializerCacheback to summary
public DeserializerCache()
DeserializerCacheback to summary
public DeserializerCache(LookupCache<JavaType, ValueDeserializer<Object>> cache)

Method Detail

_createAndCache2back to summary
protected ValueDeserializer<Object> _createAndCache2(DeserializationContext ctxt, DeserializerFactory factory, JavaType type, boolean isCustom)

Method that handles actual construction (via factory) and caching (both intermediate and eventual)

_createAndCacheValueDeserializerback to summary
protected ValueDeserializer<Object> _createAndCacheValueDeserializer(DeserializationContext ctxt, DeserializerFactory factory, JavaType type)

Method that will try to create a deserializer for given type, and resolve and cache it if necessary

Parameters
ctxt:DeserializationContext

Currently active deserialization context

type:JavaType

Type of property to deserialize (never null, callers verify)

_createDeserializerback to summary
protected ValueDeserializer<Object> _createDeserializer(DeserializationContext ctxt, DeserializerFactory factory, JavaType type)

Method that does the heavy lifting of checking for per-type annotations, find out full type, and figure out which actual factory method to call.

Annotations
@SuppressWarnings:unchecked
_createDeserializer2back to summary
protected ValueDeserializer<?> _createDeserializer2(DeserializationContext ctxt, DeserializerFactory factory, JavaType type, BeanDescription.Supplier beanDescRef)
_findCachedDeserializerback to summary
protected ValueDeserializer<Object> _findCachedDeserializer(JavaType type)
_handleUnknownKeyDeserializerback to summary
protected KeyDeserializer _handleUnknownKeyDeserializer(DeserializationContext ctxt, JavaType type)
_handleUnknownValueDeserializerback to summary
protected ValueDeserializer<Object> _handleUnknownValueDeserializer(DeserializationContext ctxt, JavaType type)
_hasCustomHandlersback to summary
private boolean _hasCustomHandlers(JavaType t)

Helper method used to prevent both caching and cache lookups for structured types that have custom value handlers

_verifyAsClassback to summary
private Class<?> _verifyAsClass(Object src, String methodName, Class<?> noneClass)
cachedDeserializersCountback to summary
public int cachedDeserializersCount()

Method that can be used to determine how many deserializers this provider is caching currently (if it does caching: default implementation does) Exact count depends on what kind of deserializers get cached; default implementation caches only dynamically constructed deserializers, but not eagerly constructed standard deserializers (which is different from how serializer provider works).

The main use case for this method is to allow conditional flushing of deserializer cache, if certain number of entries is reached.

emptyCopyback to summary
public DeserializerCache emptyCopy()
findConverterback to summary
protected Converter<Object, Object> findConverter(DeserializationContext ctxt, Annotated a)
findConvertingDeserializerback to summary
protected ValueDeserializer<Object> findConvertingDeserializer(DeserializationContext ctxt, Annotated a, ValueDeserializer<Object> deser)

Helper method that will check whether given annotated entity (usually class, but may also be a property accessor) indicates that a Converter is to be used; and if so, to construct and return suitable serializer for it. If not, will simply return given serializer as is.

findDeserializerFromAnnotationback to summary
protected ValueDeserializer<Object> findDeserializerFromAnnotation(DeserializationContext ctxt, Annotated ann)

Helper method called to check if a class or method has annotation that tells which class to use for deserialization. Returns null if no such annotation found.

findKeyDeserializerback to summary
public KeyDeserializer findKeyDeserializer(DeserializationContext ctxt, DeserializerFactory factory, JavaType type)

Method called to get hold of a deserializer to use for deserializing keys for java.util.Map.

Exceptions
DatabindException:
if there are fatal problems with accessing suitable key deserializer; including that of not finding any serializer
findValueDeserializerback to summary
public ValueDeserializer<Object> findValueDeserializer(DeserializationContext ctxt, DeserializerFactory factory, JavaType propertyType)

Method called to get hold of a deserializer for a value of given type; or if no such deserializer can be found, a default handler (which may do a best-effort generic serialization or just simply throw an exception when invoked).

Note

this method is only called for value types; not for keys. Key deserializers can be accessed using findKeyDeserializer.

Note also that deserializer returned is guaranteed to be resolved (see ValueDeserializer#resolve), but not contextualized (wrt ValueDeserializer#createContextual): caller has to handle latter if necessary.

Parameters
ctxt:DeserializationContext

Deserialization context

propertyType:JavaType

Declared type of the value to deserializer (obtained using 'setter' method signature and/or type annotations

flushCachedDeserializersback to summary
public void flushCachedDeserializers()

Method that will drop all dynamically constructed deserializers (ones that are counted as result value for cachedDeserializersCount). This can be used to remove memory usage (in case some deserializers are only used once or so), or to force re-construction of deserializers after configuration changes for mapper than owns the provider.

modifyTypeByAnnotationback to summary
private JavaType modifyTypeByAnnotation(DeserializationContext ctxt, Annotated a, JavaType type)

Method called to see if given method has annotations that indicate a more specific type than what the argument specifies. If annotations are present, they must specify compatible Class; instance of which can be assigned using the method. This means that the Class has to be raw class of type, or its sub-class (or, implementing class if original Class instance is an interface).

Parameters
a:Annotated

Method or field that the type is associated with

type:JavaType

Type derived from the setter argument

Returns:JavaType

Original type if no annotations are present; or a more specific type derived from it if type annotation(s) was found

readResolveback to summary
protected Object readResolve()