Class DeserializerCache

java.lang.Object
tools.jackson.databind.deser.DeserializerCache
All Implemented Interfaces:
Serializable

public final class DeserializerCache extends Object implements Serializable
Class that defines caching layer between callers (like ObjectMapper, DeserializationContext) and classes that construct deserializers (DeserializerFactory).
See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • DEFAULT_MAX_CACHE_SIZE

      public static final int DEFAULT_MAX_CACHE_SIZE
      Default size of the underlying cache to use.

      NOTE: reduced from 2.x default.

      See Also:
    • _cachedDeserializers

      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.
    • _incompleteDeserializers

      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.
    • _incompleteDeserializersLock

      private final ReentrantLock _incompleteDeserializersLock
      We hold an explicit lock while creating deserializers to avoid creating duplicates. Guards _incompleteDeserializers.
  • Constructor Details

  • Method Details

    • emptyCopy

      public DeserializerCache emptyCopy()
    • readResolve

      protected Object 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 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.
    • 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 (wrt ValueDeserializer.createContextual(DeserializationContext, BeanProperty)): caller has to handle latter if necessary.

      Parameters:
      ctxt - Deserialization context
      propertyType - 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 for Map.
      Throws:
      DatabindException - if there are fatal problems with accessing suitable key deserializer; including that of not finding any serializer
    • _findCachedDeserializer

      protected ValueDeserializer<Object> _findCachedDeserializer(JavaType type)
    • _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 context
      type - 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 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.
    • findConverter

      protected Converter<Object,Object> findConverter(DeserializationContext ctxt, Annotated a)
    • modifyTypeByAnnotation

      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 - Method or field that the type is associated with
      type - 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

      private boolean _hasCustomHandlers(JavaType t)
      Helper method used to prevent both caching and cache lookups for structured types that have custom value handlers
    • _verifyAsClass

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

      protected ValueDeserializer<Object> _handleUnknownValueDeserializer(DeserializationContext ctxt, JavaType type)
    • _handleUnknownKeyDeserializer

      protected KeyDeserializer _handleUnknownKeyDeserializer(DeserializationContext ctxt, JavaType type)