com.fasterxml.jackson.databind.deser

## Class DeserializerCache

- java.lang.Object
- - com.fasterxml.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:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected ConcurrentHashMap<JavaType,JsonDeserializer<Object>>` | `_cachedDeserializers` We will also cache some dynamically constructed deserializers; specifically, ones that are expensive to construct.
    `protected HashMap<JavaType,JsonDeserializer<Object>>` | `_incompleteDeserializers` During deserializer construction process we may need to keep track of partially completed deserializers, to resolve cyclic dependencies.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DeserializerCache()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected JsonDeserializer<Object>` | `_createAndCache2(DeserializationContext ctxt, DeserializerFactory factory, JavaType type)` Method that handles actual construction (via factory) and caching (both intermediate and eventual)
    `protected JsonDeserializer<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
    `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<?>` | `_createDeserializer2(DeserializationContext ctxt, DeserializerFactory factory, JavaType type, BeanDescription beanDesc)`
    `protected JsonDeserializer<Object>` | `_findCachedDeserializer(JavaType type)`
    `protected KeyDeserializer` | `_handleUnknownKeyDeserializer(JavaType type)`
    `protected JsonDeserializer<Object>` | `_handleUnknownValueDeserializer(JavaType type)`
    `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).
    `protected Converter<Object,Object>` | `findConverter(DeserializationContext ctxt, Annotated a)`
    `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.
    `KeyDeserializer` | `findKeyDeserializer(DeserializationContext ctxt, DeserializerFactory factory, JavaType type)` Method called to get hold of a deserializer to use for deserializing keys for `Map`.
    `JsonDeserializer<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).
    `void` | `flushCachedDeserializers()` Method that will drop all dynamically constructed deserializers (ones that are counted as result value for `cachedDeserializersCount()`).
    `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.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### _cachedDeserializers

          protected final ConcurrentHashMap<JavaType,JsonDeserializer<Object>> _cachedDeserializers

      We will also cache some dynamically constructed deserializers; specifically, ones that are expensive to construct. This currently means bean and Enum deserializers; array, List and Map deserializers will not be cached.

      Given that we don't expect much concurrency for additions (should very quickly converge to zero after startup), let's explicitly define a low concurrency setting.

    - #### _incompleteDeserializers

          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.

  - ### Constructor Detail

    - #### DeserializerCache

          public DeserializerCache()

  - ### Method Detail

    - #### 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 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(com.fasterxml.jackson.databind.DeserializationContext, com.fasterxml.jackson.databind.deser.DeserializerFactory, com.fasterxml.jackson.databind.JavaType)`.

      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` - Deserialization context
        `propertyType` - Declared type of the value to deserializer (obtained using 'setter' method signature and/or type annotations
      Throws:
        `JsonMappingException` - if there are fatal problems with accessing suitable deserializer; including that of not finding any serializer

    - #### findKeyDeserializer

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

    - #### hasValueDeserializerFor

          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)
      Throws:
        `JsonMappingException`

    - #### _findCachedDeserializer

          protected JsonDeserializer<Object> _findCachedDeserializer(JavaType type)

    - #### _createAndCacheValueDeserializer

          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` - Currently active deserialization context
        `type` - Type of property to deserialize
      Throws:
        `JsonMappingException`

    - #### _createAndCache2

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

      Method that handles actual construction (via factory) and caching (both intermediate and eventual)
      Throws:
        `JsonMappingException`

    - #### _createDeserializer

          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.
      Throws:
        `JsonMappingException`

    - #### _createDeserializer2

          protected JsonDeserializer<?> _createDeserializer2(DeserializationContext ctxt,
                                                 DeserializerFactory factory,
                                                 JavaType type,
                                                 BeanDescription beanDesc)
                                                      throws JsonMappingException

      Throws:
        `JsonMappingException`

    - #### findDeserializerFromAnnotation

          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.
      Throws:
        `JsonMappingException`

    - #### findConvertingDeserializer

          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.
      Throws:
        `JsonMappingException`

    - #### findConverter

          protected Converter<Object,Object> findConverter(DeserializationContext ctxt,
                                               Annotated a)
                                                    throws JsonMappingException

      Throws:
        `JsonMappingException`

    - #### _handleUnknownValueDeserializer

          protected JsonDeserializer<Object> _handleUnknownValueDeserializer(JavaType type)
                                                                      throws JsonMappingException

      Throws:
        `JsonMappingException`

    - #### _handleUnknownKeyDeserializer

          protected KeyDeserializer _handleUnknownKeyDeserializer(JavaType type)
                                                           throws JsonMappingException

      Throws:
        `JsonMappingException`

Copyright © 2012-2013 FasterXML. All Rights Reserved.