Class DeserializerCache
java.lang.Object
tools.jackson.databind.deser.DeserializerCache
- All Implemented Interfaces:
Serializable
Class that defines caching layer between callers (like
ObjectMapper,
DeserializationContext)
and classes that construct deserializers
(DeserializerFactory).- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final LookupCache<JavaType, ValueDeserializer<Object>> We will also cache some dynamically constructed deserializers; specifically, ones that are expensive to construct.private final HashMap<JavaType, ValueDeserializer<Object>> During deserializer construction process we may need to keep track of partially completed deserializers, to resolve cyclic dependencies.private final ReentrantLockWe hold an explicit lock while creating deserializers to avoid creating duplicates.static final intDefault size of the underlying cache to use.private static final long -
Constructor Summary
ConstructorsConstructorDescription -
Method Summary
Modifier and TypeMethodDescriptionprotected 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 ctxt, DeserializerFactory factory, JavaType type) Method that will try to create a deserializer for given type, and resolve and cache it if necessaryprotected 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<?> _createDeserializer2(DeserializationContext ctxt, DeserializerFactory factory, JavaType type, BeanDescription.Supplier beanDescRef) protected ValueDeserializer<Object> protected KeyDeserializerprotected ValueDeserializer<Object> private booleanHelper method used to prevent both caching and cache lookups for structured types that have custom value handlersprivate Class<?> _verifyAsClass(Object src, String methodName, Class<?> noneClass) intMethod 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).findConverter(DeserializationContext ctxt, Annotated a) 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 aConverteris to be used; and if so, to construct and return suitable serializer for it.protected ValueDeserializer<Object> Helper method called to check if a class or method has annotation that tells which class to use for deserialization.findKeyDeserializer(DeserializationContext ctxt, DeserializerFactory factory, JavaType type) Method called to get hold of a deserializer to use for deserializing keys forMap.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).voidMethod that will drop all dynamically constructed deserializers (ones that are counted as result value forcachedDeserializersCount()).private JavaTypemodifyTypeByAnnotation(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.protected Object
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
DEFAULT_MAX_CACHE_SIZE
public static final int DEFAULT_MAX_CACHE_SIZEDefault size of the underlying cache to use.NOTE: reduced from 2.x default.
- See Also:
-
_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. -
_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. -
_incompleteDeserializersLock
We hold an explicit lock while creating deserializers to avoid creating duplicates. Guards_incompleteDeserializers.
-
-
Constructor Details
-
DeserializerCache
public DeserializerCache() -
DeserializerCache
-
-
Method Details
-
emptyCopy
-
readResolve
-
cachedDeserializersCount
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.
-
flushCachedDeserializers
public void flushCachedDeserializers()Method that will drop all dynamically constructed deserializers (ones that are counted as result value forcachedDeserializersCount()). 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. -
findValueDeserializer
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(DeserializationContext, DeserializerFactory, JavaType).Note also that deserializer returned is guaranteed to be resolved (see
ValueDeserializer.resolve(DeserializationContext)), but not contextualized (wrtValueDeserializer.createContextual(DeserializationContext, BeanProperty)): caller has to handle latter if necessary.- Parameters:
ctxt- Deserialization contextpropertyType- Declared type of the value to deserializer (obtained using 'setter' method signature and/or type annotations
-
findKeyDeserializer
public KeyDeserializer findKeyDeserializer(DeserializationContext ctxt, DeserializerFactory factory, JavaType type) Method called to get hold of a deserializer to use for deserializing keys forMap.- Throws:
DatabindException- if there are fatal problems with accessing suitable key deserializer; including that of not finding any serializer
-
_findCachedDeserializer
-
_createAndCacheValueDeserializer
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- Currently active deserialization contexttype- Type of property to deserialize (never null, callers verify)
-
_createAndCache2
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) -
_createDeserializer
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. -
_createDeserializer2
protected ValueDeserializer<?> _createDeserializer2(DeserializationContext ctxt, DeserializerFactory factory, JavaType type, BeanDescription.Supplier beanDescRef) -
findDeserializerFromAnnotation
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. -
findConvertingDeserializer
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 aConverteris to be used; and if so, to construct and return suitable serializer for it. If not, will simply return given serializer as is. -
findConverter
-
modifyTypeByAnnotation
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- Method or field that the type is associated withtype- Type derived from the setter argument- Returns:
- Original type if no annotations are present; or a more specific type derived from it if type annotation(s) was found
-
_hasCustomHandlers
Helper method used to prevent both caching and cache lookups for structured types that have custom value handlers -
_verifyAsClass
-
_handleUnknownValueDeserializer
protected ValueDeserializer<Object> _handleUnknownValueDeserializer(DeserializationContext ctxt, JavaType type) -
_handleUnknownKeyDeserializer
-