com.fasterxml.jackson.databind

## Class DeserializationContext

- java.lang.Object
- - com.fasterxml.jackson.databind.DatabindContext
  - - com.fasterxml.jackson.databind.DeserializationContext

- All Implemented Interfaces:
    Serializable
  Direct Known Subclasses:
    DefaultDeserializationContext

      public abstract class DeserializationContext
      extends DatabindContext
      implements Serializable

  Context for the process of deserialization a single root-level value. Used to allow passing in configuration settings and reusable temporary objects (scrap arrays, containers).

  Instance life-cycle is such that an partially configured "blueprint" object is registered with `ObjectMapper` (and `ObjectReader`, and when an actual instance is needed for deserialization, a fully configured instance will be created using a method in excented API of sub-class (`DefaultDeserializationContext.createInstance(com.fasterxml.jackson.databind.DeserializationConfig, com.fasterxml.jackson.core.JsonParser, com.fasterxml.jackson.databind.InjectableValues)`). Each instance is guaranteed to only be used from single-threaded context; instances may be reused iff no configuration has changed.

  Defined as abstract class so that implementations must define methods for reconfiguring blueprints and creating instances.

  See Also:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected ArrayBuilders` | `_arrayBuilders`
    `protected ContextAttributes` | `_attributes` Lazily-constructed holder for per-call attributes.
    `protected DeserializerCache` | `_cache` Object that handle details of `JsonDeserializer` caching.
    `protected DeserializationConfig` | `_config` Generic deserialization processing configuration
    `protected DateFormat` | `_dateFormat`
    `protected DeserializerFactory` | `_factory` Read-only factory instance; exposed to let owners (`ObjectMapper`, `ObjectReader`) access it.
    `protected int` | `_featureFlags` Bitmap of `DeserializationFeature`s that are enabled
    `protected InjectableValues` | `_injectableValues` Object used for resolving references to injectable values.
    `protected ObjectBuffer` | `_objectBuffer`
    `protected JsonParser` | `_parser` Currently active parser used for deserialization.
    `protected Class<?>` | `_view` Currently active view, if any.

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `DeserializationContext(DeserializationContext src, DeserializationConfig config, JsonParser jp, InjectableValues injectableValues)` Constructor used for creating actual per-call instances.
    `protected` | `DeserializationContext(DeserializationContext src, DeserializerFactory factory)`
    `protected` | `DeserializationContext(DeserializerFactory df)`
    `protected` | `DeserializationContext(DeserializerFactory df, DeserializerCache cache)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected String` | `_calcName(Class<?> cls)`
    `protected String` | `_desc(String desc)`
    `protected String` | `_valueDesc()`
    `Calendar` | `constructCalendar(Date d)` Convenience method for constructing Calendar instance set to specified time, to be modified and used by caller.
    `JavaType` | `constructType(Class<?> cls)` Convenience method, functionally equivalent to:
    `abstract JsonDeserializer<Object>` | `deserializerInstance(Annotated annotated, Object deserDef)`
    `protected String` | `determineClassName(Object instance)`
    `JsonMappingException` | `endOfInputException(Class<?> instClass)`
    `Class<?>` | `findClass(String className)` Helper method to use for locating Class for given name.
    `JsonDeserializer<Object>` | `findContextualValueDeserializer(JavaType type, BeanProperty property)` Method for finding a value deserializer, and creating a contextual version if necessary, for value reached via specified property.
    `Object` | `findInjectableValue(Object valueId, BeanProperty forProperty, Object beanInstance)`
    `KeyDeserializer` | `findKeyDeserializer(JavaType keyType, BeanProperty property)` Convenience method, functionally same as:
    `abstract ReadableObjectId` | `findObjectId(Object id, ObjectIdGenerator<?> generator)` Method called to find and return entry corresponding to given Object Id: will add an entry if necessary, and never returns null
    `JsonDeserializer<Object>` | `findRootValueDeserializer(JavaType type)` Method for finding a deserializer for root-level value.
    `Class<?>` | `getActiveView()` Accessor for locating currently active view, if any; returns null if no view has been set.
    `AnnotationIntrospector` | `getAnnotationIntrospector()` Convenience method for accessing serialization view in use (if any); equivalent to:
    `ArrayBuilders` | `getArrayBuilders()` Method for accessing object useful for building arrays of primitive types (such as int[]).
    `Object` | `getAttribute(Object key)` Method for accessing attributes available in this context.
    `Base64Variant` | `getBase64Variant()` Convenience method for accessing the default Base64 encoding used for decoding base64 encoded binary content.
    `DeserializationConfig` | `getConfig()` Accessor to currently active configuration (both per-request configs and per-mapper config).
    `protected DateFormat` | `getDateFormat()`
    `DeserializerFactory` | `getFactory()` Method for getting current `DeserializerFactory`.
    `Locale` | `getLocale()` Method for accessing default Locale to use: convenience method for
    `JsonNodeFactory` | `getNodeFactory()` Convenience method, functionally equivalent to:
    `JsonParser` | `getParser()` Method for accessing the currently active parser.
    `TimeZone` | `getTimeZone()` Method for accessing default TimeZone to use: convenience method for
    `TypeFactory` | `getTypeFactory()`
    `JsonDeserializer<?>` | `handlePrimaryContextualization(JsonDeserializer<?> deser, BeanProperty property)` Method called for primary property deserializers (ones directly created to deserialize values of a POJO property), to handle details of resolving `ContextualDeserializer` with given property context.
    `JsonDeserializer<?>` | `handleSecondaryContextualization(JsonDeserializer<?> deser, BeanProperty property)` Method called for secondary property deserializers (ones NOT directly created to deal with an annotatable POJO property, but instead created as a component -- such as value deserializers for structured types, or deserializers for root values) to handle details of resolving `ContextualDeserializer` with given property context.
    `boolean` | `handleUnknownProperty(JsonParser jp, JsonDeserializer<?> deser, Object instanceOrClass, String propName)` Method deserializers can call to inform configured `DeserializationProblemHandler`s of an unrecognized property.
    `boolean` | `hasDeserializationFeatures(int featureMask)` "Bulk" access method for checking that all features specified by mask are enabled.
    `boolean` | `hasValueDeserializerFor(JavaType type)` Deprecated.
    `boolean` | `hasValueDeserializerFor(JavaType type, AtomicReference<Throwable> cause)` Method for checking whether we could find a deserializer for given type.
    `JsonMappingException` | `instantiationException(Class<?> instClass, String msg)`
    `JsonMappingException` | `instantiationException(Class<?> instClass, Throwable t)` Helper method for constructing instantiation exception for specified type, to indicate problem with physically constructing instance of specified class (missing constructor, exception from constructor)
    `boolean` | `isEnabled(DeserializationFeature feat)` Convenience method for checking whether specified on/off feature is enabled
    `abstract KeyDeserializer` | `keyDeserializerInstance(Annotated annotated, Object deserDef)`
    `ObjectBuffer` | `leaseObjectBuffer()` Method that can be used to get access to a reusable ObjectBuffer, useful for efficiently constructing Object arrays and Lists.
    `JsonMappingException` | `mappingException(Class<?> targetClass)` Helper method for constructing generic mapping exception for specified type
    `JsonMappingException` | `mappingException(Class<?> targetClass, JsonToken token)`
    `JsonMappingException` | `mappingException(String message)` Helper method for constructing generic mapping exception with specified message and current location information
    `Date` | `parseDate(String dateStr)` Convenience method for parsing a Date from given String, using currently configured date format (accessed using `MapperConfig.getDateFormat()`).
    `void` | `reportUnknownProperty(Object instanceOrClass, String fieldName, JsonDeserializer<?> deser)` Helper method for reporting a problem with unhandled unknown exception
    `void` | `returnObjectBuffer(ObjectBuffer buf)` Method to call to return object buffer previously leased with `leaseObjectBuffer()`.
    `DeserializationContext` | `setAttribute(Object key, Object value)` Method for setting per-call value of given attribute.
    `JsonMappingException` | `unknownTypeException(JavaType type, String id)` Helper method for constructing exception to indicate that given type id (parsed from JSON) could not be converted to a Java type.
    `JsonMappingException` | `weirdKeyException(Class<?> keyClass, String keyValue, String msg)` Helper method for constructing exception to indicate that given JSON Object field name was not in format to be able to deserialize specified key type.
    `JsonMappingException` | `weirdNumberException(Class<?> instClass, String msg)` Deprecated.
    `JsonMappingException` | `weirdNumberException(Number value, Class<?> instClass, String msg)` Helper method for constructing exception to indicate that input JSON Number was not suitable for deserializing into given target type.
    `JsonMappingException` | `weirdStringException(Class<?> instClass, String msg)` Deprecated. Since 2.1 should use variant that takes value
    `JsonMappingException` | `weirdStringException(String value, Class<?> instClass, String msg)` Method that will construct an exception suitable for throwing when some String values are acceptable, but the one encountered is not.
    `JsonMappingException` | `wrongTokenException(JsonParser jp, JsonToken expToken, String msg)` Helper method for indicating that the current token was expected to be another token.

    - ### Methods inherited from class com.fasterxml.jackson.databind.DatabindContext

      `canOverrideAccessModifiers, constructSpecializedType, constructType, converterInstance, isEnabled, objectIdGeneratorInstance`

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

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

- - ### Field Detail

    - #### _cache

          protected final DeserializerCache _cache

      Object that handle details of `JsonDeserializer` caching.

    - #### _factory

          protected final DeserializerFactory _factory

      Read-only factory instance; exposed to let owners (`ObjectMapper`, `ObjectReader`) access it.

    - #### _config

          protected final DeserializationConfig _config

      Generic deserialization processing configuration

    - #### _featureFlags

          protected final int _featureFlags

      Bitmap of `DeserializationFeature`s that are enabled

    - #### _view

          protected final Class<?> _view

      Currently active view, if any.

    - #### _parser

          protected transient JsonParser _parser

      Currently active parser used for deserialization. May be different from the outermost parser when content is buffered.

    - #### _injectableValues

          protected final InjectableValues _injectableValues

      Object used for resolving references to injectable values.

    - #### _arrayBuilders

          protected transient ArrayBuilders _arrayBuilders

    - #### _objectBuffer

          protected transient ObjectBuffer _objectBuffer

    - #### _dateFormat

          protected transient DateFormat _dateFormat

    - #### _attributes

          protected transient ContextAttributes _attributes

      Lazily-constructed holder for per-call attributes.
      Since:
        2.3

  - ### Constructor Detail

    - #### DeserializationContext

          protected DeserializationContext(DeserializerFactory df)

    - #### DeserializationContext

          protected DeserializationContext(DeserializerFactory df,
                                DeserializerCache cache)

    - #### DeserializationContext

          protected DeserializationContext(DeserializationContext src,
                                DeserializerFactory factory)

    - #### DeserializationContext

          protected DeserializationContext(DeserializationContext src,
                                DeserializationConfig config,
                                JsonParser jp,
                                InjectableValues injectableValues)

      Constructor used for creating actual per-call instances.

  - ### Method Detail

    - #### getConfig

          public DeserializationConfig getConfig()

      Description copied from class: `DatabindContext`
      Accessor to currently active configuration (both per-request configs and per-mapper config).
      Specified by:
        `getConfig` in class `DatabindContext`

    - #### getActiveView

          public final Class<?> getActiveView()

      Description copied from class: `DatabindContext`
      Accessor for locating currently active view, if any; returns null if no view has been set.
      Specified by:
        `getActiveView` in class `DatabindContext`

    - #### getAnnotationIntrospector

          public final AnnotationIntrospector getAnnotationIntrospector()

      Description copied from class: `DatabindContext`
      Convenience method for accessing serialization view in use (if any); equivalent to:

             getConfig().getAnnotationIntrospector();

      Specified by:
        `getAnnotationIntrospector` in class `DatabindContext`

    - #### getTypeFactory

          public final TypeFactory getTypeFactory()

      Specified by:
        `getTypeFactory` in class `DatabindContext`

    - #### getAttribute

          public Object getAttribute(Object key)

      Description copied from class: `DatabindContext`
      Method for accessing attributes available in this context. Per-call attributes have highest precedence; attributes set via `ObjectReader` or `ObjectWriter` have lower precedence.
      Specified by:
        `getAttribute` in class `DatabindContext`
      Parameters:
        `key` - Key of the attribute to get
      Returns:
        Value of the attribute, if any; null otherwise

    - #### setAttribute

          public DeserializationContext setAttribute(Object key,
                                            Object value)

      Description copied from class: `DatabindContext`
      Method for setting per-call value of given attribute. This will override any previously defined value for the attribute within this context.
      Specified by:
        `setAttribute` in class `DatabindContext`
      Parameters:
        `key` - Key of the attribute to set
        `value` - Value to set attribute to
      Returns:
        This context object, to allow chaining

    - #### getFactory

          public DeserializerFactory getFactory()

      Method for getting current `DeserializerFactory`.

    - #### isEnabled

          public final boolean isEnabled(DeserializationFeature feat)

      Convenience method for checking whether specified on/off feature is enabled

    - #### hasDeserializationFeatures

          public final boolean hasDeserializationFeatures(int featureMask)

      "Bulk" access method for checking that all features specified by mask are enabled.
      Since:
        2.3

    - #### getParser

          public final JsonParser getParser()

      Method for accessing the currently active parser. May be different from the outermost parser when content is buffered.

      Use of this method is discouraged: if code has direct access to the active parser, that should be used instead.

    - #### findInjectableValue

          public final Object findInjectableValue(Object valueId,
                                   BeanProperty forProperty,
                                   Object beanInstance)

    - #### getBase64Variant

          public final Base64Variant getBase64Variant()

      Convenience method for accessing the default Base64 encoding used for decoding base64 encoded binary content. Same as calling:

            getConfig().getBase64Variant();

    - #### getNodeFactory

          public final JsonNodeFactory getNodeFactory()

      Convenience method, functionally equivalent to:

            getConfig().getNodeFactory();

    - #### getLocale

          public Locale getLocale()

      Method for accessing default Locale to use: convenience method for

             getConfig().getLocale();

    - #### getTimeZone

          public TimeZone getTimeZone()

      Method for accessing default TimeZone to use: convenience method for

             getConfig().getTimeZone();

    - #### hasValueDeserializerFor

          @Deprecated
          public boolean hasValueDeserializerFor(JavaType type)

      Deprecated.

    - #### hasValueDeserializerFor

          public boolean hasValueDeserializerFor(JavaType type,
                                        AtomicReference<Throwable> cause)

      Method for checking whether we could find a deserializer for given type.
      Parameters:
        `type` -
      Since:
        2.3

    - #### findContextualValueDeserializer

          public final JsonDeserializer<Object> findContextualValueDeserializer(JavaType type,
                                                                 BeanProperty property)
                                                                         throws JsonMappingException

      Method for finding a value deserializer, and creating a contextual version if necessary, for value reached via specified property.
      Throws:
        `JsonMappingException`

    - #### findRootValueDeserializer

          public final JsonDeserializer<Object> findRootValueDeserializer(JavaType type)
                                                                   throws JsonMappingException

      Method for finding a deserializer for root-level value.
      Throws:
        `JsonMappingException`

    - #### findKeyDeserializer

          public final KeyDeserializer findKeyDeserializer(JavaType keyType,
                                            BeanProperty property)
                                                    throws JsonMappingException

      Convenience method, functionally same as:

            getDeserializerProvider().findKeyDeserializer(getConfig(), propertyType, property);

      Throws:
        `JsonMappingException`

    - #### findObjectId

          public abstract ReadableObjectId findObjectId(Object id,
                                      ObjectIdGenerator<?> generator)

      Method called to find and return entry corresponding to given Object Id: will add an entry if necessary, and never returns null

    - #### constructType

          public final JavaType constructType(Class<?> cls)

      Convenience method, functionally equivalent to:

            getConfig().constructType(cls);

    - #### findClass

          public Class<?> findClass(String className)
                             throws ClassNotFoundException

      Helper method to use for locating Class for given name. Should be used instead of basic `Class.forName(className);` as it can try using contextual class loader, or use platform-specific workarounds (like on Android, GAE).
      Throws:
        `ClassNotFoundException`

    - #### leaseObjectBuffer

          public final ObjectBuffer leaseObjectBuffer()

      Method that can be used to get access to a reusable ObjectBuffer, useful for efficiently constructing Object arrays and Lists. Note that leased buffers should be returned once deserializer is done, to allow for reuse during same round of deserialization.

    - #### returnObjectBuffer

          public final void returnObjectBuffer(ObjectBuffer buf)

      Method to call to return object buffer previously leased with `leaseObjectBuffer()`.
      Parameters:
        `buf` - Returned object buffer

    - #### getArrayBuilders

          public final ArrayBuilders getArrayBuilders()

      Method for accessing object useful for building arrays of primitive types (such as int[]).

    - #### deserializerInstance

          public abstract JsonDeserializer<Object> deserializerInstance(Annotated annotated,
                                                      Object deserDef)
                                                                 throws JsonMappingException

      Throws:
        `JsonMappingException`

    - #### keyDeserializerInstance

          public abstract KeyDeserializer keyDeserializerInstance(Annotated annotated,
                                                Object deserDef)
                                                           throws JsonMappingException

      Throws:
        `JsonMappingException`

    - #### handlePrimaryContextualization

          public JsonDeserializer<?> handlePrimaryContextualization(JsonDeserializer<?> deser,
                                                           BeanProperty property)
                                                             throws JsonMappingException

      Method called for primary property deserializers (ones directly created to deserialize values of a POJO property), to handle details of resolving `ContextualDeserializer` with given property context.
      Parameters:
        `property` - Property for which the given primary deserializer is used; never null.
      Throws:
        `JsonMappingException`
      Since:
        2.3

    - #### handleSecondaryContextualization

          public JsonDeserializer<?> handleSecondaryContextualization(JsonDeserializer<?> deser,
                                                             BeanProperty property)
                                                               throws JsonMappingException

      Method called for secondary property deserializers (ones NOT directly created to deal with an annotatable POJO property, but instead created as a component -- such as value deserializers for structured types, or deserializers for root values) to handle details of resolving `ContextualDeserializer` with given property context. Given that these deserializers are not directly related to given property (or, in case of root value property, to any property), annotations accessible may or may not be relevant.
      Parameters:
        `property` - Property for which deserializer is used, if any; null when deserializing root values
      Throws:
        `JsonMappingException`
      Since:
        2.3

    - #### parseDate

          public Date parseDate(String dateStr)
                         throws IllegalArgumentException

      Convenience method for parsing a Date from given String, using currently configured date format (accessed using `MapperConfig.getDateFormat()`).

      Implementation will handle thread-safety issues related to date formats such that first time this method is called, date format is cloned, and cloned instance will be retained for use during this deserialization round.

      Throws:
        `IllegalArgumentException`

    - #### constructCalendar

          public Calendar constructCalendar(Date d)

      Convenience method for constructing Calendar instance set to specified time, to be modified and used by caller.

    - #### handleUnknownProperty

          public boolean handleUnknownProperty(JsonParser jp,
                                      JsonDeserializer<?> deser,
                                      Object instanceOrClass,
                                      String propName)
                                        throws IOException,
                                               JsonProcessingException

      Method deserializers can call to inform configured `DeserializationProblemHandler`s of an unrecognized property.
      Throws:
        `IOException`
        `JsonProcessingException`

    - #### reportUnknownProperty

          public void reportUnknownProperty(Object instanceOrClass,
                                   String fieldName,
                                   JsonDeserializer<?> deser)
                                     throws JsonMappingException

      Helper method for reporting a problem with unhandled unknown exception
      Parameters:
        `instanceOrClass` - Either value being populated (if one has been instantiated), or Class that indicates type that would be (or have been) instantiated
        `deser` - Deserializer that had the problem, if called by deserializer (or on behalf of one)
      Throws:
        `JsonMappingException`

    - #### mappingException

          public JsonMappingException mappingException(Class<?> targetClass)

      Helper method for constructing generic mapping exception for specified type

    - #### mappingException

          public JsonMappingException mappingException(Class<?> targetClass,
                                              JsonToken token)

    - #### mappingException

          public JsonMappingException mappingException(String message)

      Helper method for constructing generic mapping exception with specified message and current location information

    - #### instantiationException

          public JsonMappingException instantiationException(Class<?> instClass,
                                                    Throwable t)

      Helper method for constructing instantiation exception for specified type, to indicate problem with physically constructing instance of specified class (missing constructor, exception from constructor)

    - #### instantiationException

          public JsonMappingException instantiationException(Class<?> instClass,
                                                    String msg)

    - #### weirdStringException

          @Deprecated
          public JsonMappingException weirdStringException(Class<?> instClass,
                                                             String msg)

      Deprecated. Since 2.1 should use variant that takes value
      Method that will construct an exception suitable for throwing when some String values are acceptable, but the one encountered is not.

    - #### weirdStringException

          public JsonMappingException weirdStringException(String value,
                                                  Class<?> instClass,
                                                  String msg)

      Method that will construct an exception suitable for throwing when some String values are acceptable, but the one encountered is not.
      Parameters:
        `value` - String value from input being deserialized
        `instClass` - Type that String should be deserialized into
        `msg` - Message that describes specific problem
      Since:
        2.1

    - #### weirdNumberException

          @Deprecated
          public JsonMappingException weirdNumberException(Class<?> instClass,
                                                             String msg)

      Deprecated.
      Helper method for constructing exception to indicate that input JSON Number was not suitable for deserializing into given type.

    - #### weirdNumberException

          public JsonMappingException weirdNumberException(Number value,
                                                  Class<?> instClass,
                                                  String msg)

      Helper method for constructing exception to indicate that input JSON Number was not suitable for deserializing into given target type.

    - #### weirdKeyException

          public JsonMappingException weirdKeyException(Class<?> keyClass,
                                               String keyValue,
                                               String msg)

      Helper method for constructing exception to indicate that given JSON Object field name was not in format to be able to deserialize specified key type.

    - #### wrongTokenException

          public JsonMappingException wrongTokenException(JsonParser jp,
                                                 JsonToken expToken,
                                                 String msg)

      Helper method for indicating that the current token was expected to be another token.

    - #### unknownTypeException

          public JsonMappingException unknownTypeException(JavaType type,
                                                  String id)

      Helper method for constructing exception to indicate that given type id (parsed from JSON) could not be converted to a Java type.

    - #### endOfInputException

          public JsonMappingException endOfInputException(Class<?> instClass)

    - #### getDateFormat

          protected DateFormat getDateFormat()

    - #### determineClassName

          protected String determineClassName(Object instance)

    - #### _calcName

          protected String _calcName(Class<?> cls)

    - #### _valueDesc

          protected String _valueDesc()

    - #### _desc

          protected String _desc(String desc)

Copyright © 2012-2013 FasterXML. All Rights Reserved.