Top Description Fields Constructors Methods
com.fasterxml.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, com.fasterxml.jackson.databind.*, com.fasterxml.jackson.databind.deser.std.StdDelegatingDeserializer, com.fasterxml.jackson.databind.introspect.Annotated, com.fasterxml.jackson.databind.type.*, com.fasterxml.jackson.databind.util.ClassUtil, .Converter, .LRUMap, .LookupCache

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

Field Summary

Modifier and TypeField and Description
protected final LookupCache<JavaType, JsonDeserializer<Object>>
_cachedDeserializers

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

protected final HashMap<JavaType, JsonDeserializer<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
DeserializerCache(int maxSize)

public

Method Summary

Modifier and TypeMethod and Description
protected JsonDeserializer<Object>
_createAndCache2(DeserializationContext ctxt, DeserializerFactory factory, JavaType type)
Deprecated Since 2.18 use version of _createAndCache2 that takes `isCustom` flag

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

protected JsonDeserializer<Object>
protected JsonDeserializer<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 JsonDeserializer<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 JsonDeserializer<?>
protected JsonDeserializer<Object>
protected KeyDeserializer
protected JsonDeserializer<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 JsonDeserializer<Object>
findConvertingDeserializer(DeserializationContext ctxt, Annotated a, JsonDeserializer<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 JsonDeserializer<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 JsonDeserializer<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).

public boolean
hasValueDeserializerFor(DeserializationContext ctxt, DeserializerFactory factory, JavaType type)

Method called to find out whether provider would be able to find a deserializer for given type, using a root reference (i.e. not through fields or membership in an array or collection)

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.

pack-priv Object
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_cachedDeserializersback to summary
protected final LookupCache<JavaType, JsonDeserializer<Object>> _cachedDeserializers

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

_incompleteDeserializersback to summary
protected final HashMap<JavaType, JsonDeserializer<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.

Since
2.17
DEFAULT_MAX_CACHE_SIZEback to summary
public static final int DEFAULT_MAX_CACHE_SIZE

Default size of the underlying cache to use.

Since
2.16
serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

DeserializerCacheback to summary
public DeserializerCache()
DeserializerCacheback to summary
public DeserializerCache(int maxSize)
DeserializerCacheback to summary
public DeserializerCache(LookupCache<JavaType, JsonDeserializer<Object>> cache)
Since
2.16

Method Detail

_createAndCache2back to summary
protected JsonDeserializer<Object> _createAndCache2(DeserializationContext ctxt, DeserializerFactory factory, JavaType type) throws JsonMappingException

Deprecated

Since 2.18 use version of _createAndCache2 that takes `isCustom` flag

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

Annotations
@Deprecated
_createAndCache2back to summary
protected JsonDeserializer<Object> _createAndCache2(DeserializationContext ctxt, DeserializerFactory factory, JavaType type, boolean isCustom) throws JsonMappingException
_createAndCacheValueDeserializerback to summary
protected JsonDeserializer<Object> _createAndCacheValueDeserializer(DeserializationContext ctxt, DeserializerFactory factory, JavaType type) throws JsonMappingException

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 JsonDeserializer<Object> _createDeserializer(DeserializationContext ctxt, DeserializerFactory factory, JavaType type) throws JsonMappingException

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 JsonDeserializer<?> _createDeserializer2(DeserializationContext ctxt, DeserializerFactory factory, JavaType type, BeanDescription beanDesc) throws JsonMappingException
_findCachedDeserializerback to summary
protected JsonDeserializer<Object> _findCachedDeserializer(JavaType type)
_handleUnknownKeyDeserializerback to summary
protected KeyDeserializer _handleUnknownKeyDeserializer(DeserializationContext ctxt, JavaType type) throws JsonMappingException
_handleUnknownValueDeserializerback to summary
protected JsonDeserializer<Object> _handleUnknownValueDeserializer(DeserializationContext ctxt, JavaType type) throws JsonMappingException
_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

Since
2.8.11
_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()
Since
2.16
findConverterback to summary
protected Converter<Object, Object> findConverter(DeserializationContext ctxt, Annotated a) throws JsonMappingException
findConvertingDeserializerback to summary
protected JsonDeserializer<Object> findConvertingDeserializer(DeserializationContext ctxt, Annotated a, JsonDeserializer<Object> deser) throws JsonMappingException

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 JsonDeserializer<Object> findDeserializerFromAnnotation(DeserializationContext ctxt, Annotated ann) throws JsonMappingException

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) throws JsonMappingException

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

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

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 (if it is of type ResolvableDeserializer), but not contextualized (wrt ContextualDeserializer): 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

Exceptions
JsonMappingException:
if there are fatal problems with accessing suitable deserializer; including that of not finding any serializer
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.

hasValueDeserializerForback to summary
public boolean hasValueDeserializerFor(DeserializationContext ctxt, DeserializerFactory factory, JavaType type) throws JsonMappingException

Method called to find out whether provider would be able to find a deserializer for given type, using a root reference (i.e. not through fields or membership in an array or collection)

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

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

Exceptions
JsonMappingException:
if invalid annotation is found
writeReplaceback to summary
pack-priv Object writeReplace()