Class StdDeserializer<T>

java.lang.Object
tools.jackson.databind.ValueDeserializer<T>
tools.jackson.databind.deser.std.StdDeserializer<T>
All Implemented Interfaces:
NullValueProvider, ValueInstantiator.Gettable
Direct Known Subclasses:
BaseNodeDeserializer, BeanDeserializerBase, ContainerDeserializerBase, DelegatingDeserializer, EnumSetDeserializer, FailingDeserializer, NullifyingDeserializer, PrimitiveArrayDeserializers, ReferenceTypeDeserializer, StdConvertingDeserializer, StdNodeBasedDeserializer, StdScalarDeserializer, StringArrayDeserializer, UnsupportedTypeDeserializer, UntypedObjectDeserializer

public abstract class StdDeserializer<T> extends ValueDeserializer<T> implements ValueInstantiator.Gettable
Base class for common deserializers. Contains shared base functionality for dealing with primitive values, such as (re)parsing from String.
  • Field Details

    • F_MASK_INT_COERCIONS

      protected static final int F_MASK_INT_COERCIONS
      Bitmask that covers DeserializationFeature.USE_BIG_INTEGER_FOR_INTS and DeserializationFeature.USE_LONG_FOR_INTS, used for more efficient cheks when coercing integral values for untyped deserialization.
    • _valueClass

      protected final Class<?> _valueClass
      Type of values this deserializer handles: sometimes exact types, other times most specific supertype of types deserializer handles (which may be as generic as Object in some case)
    • _valueType

      protected final JavaType _valueType
  • Constructor Details

  • Method Details

    • handledType

      public Class<?> handledType()
      Description copied from class: ValueDeserializer
      Method for accessing concrete physical type of values this deserializer produces. Note that this information is not guaranteed to be exact -- it may be a more generic (super-type) -- but it should not be incorrect (return a non-related type).

      Default implementation will return null, which means almost same same as returning Object.class would; that is, that nothing is known about handled type.

      Overrides:
      handledType in class ValueDeserializer<T>
      Returns:
      Physical type of values this deserializer produces, if known; null if not
    • getValueType

      public JavaType getValueType()
      Exact structured type this deserializer handles, if known.
    • getValueType

      public JavaType getValueType(DeserializationContext ctxt)
      Convenience method for getting handled type as JavaType, regardless of whether deserializer has one already resolved (and accessible via getValueType()) or not: equivalent to:
         if (getValueType() != null) {
              return getValueType();
         }
         return ctxt.constructType(handledType());
      
      Since:
      2.10
    • getValueInstantiator

      public ValueInstantiator getValueInstantiator()
      Specified by:
      getValueInstantiator in interface ValueInstantiator.Gettable
      Since:
      2.12
    • isDefaultDeserializer

      protected boolean isDefaultDeserializer(ValueDeserializer<?> deserializer)
      Method that can be called to determine if given deserializer is the default deserializer Jackson uses; as opposed to a custom deserializer installed by a module or calling application. Determination is done using JacksonStdImpl annotation on deserializer class.
    • isDefaultKeyDeserializer

      protected boolean isDefaultKeyDeserializer(KeyDeserializer keyDeser)
    • deserializeWithType

      public Object deserializeWithType(tools.jackson.core.JsonParser p, DeserializationContext ctxt, TypeDeserializer typeDeserializer) throws tools.jackson.core.JacksonException
      Base implementation that does not assume specific type inclusion mechanism. Sub-classes are expected to override this method if they are to handle type information.
      Overrides:
      deserializeWithType in class ValueDeserializer<T>
      typeDeserializer - Deserializer to use for handling type information
      Throws:
      tools.jackson.core.JacksonException
    • _deserializeFromArray

      protected T _deserializeFromArray(tools.jackson.core.JsonParser p, DeserializationContext ctxt) throws tools.jackson.core.JacksonException
      Helper method that allows easy support for array-related coercion features: checks for either empty array, or single-value array-wrapped value (if coercion enabled by CoercionConfigs (since 2.12), and either reports an exception (if no coercion allowed), or returns appropriate result value using coercion mechanism indicated.

      This method should NOT be called if Array representation is explicitly supported for type: it should only be called in case it is otherwise unrecognized.

      NOTE: in case of unwrapped single element, will handle actual decoding by calling _deserializeWrappedValue(tools.jackson.core.JsonParser, tools.jackson.databind.DeserializationContext), which by default calls ValueDeserializer.deserialize(JsonParser, DeserializationContext).

      Throws:
      tools.jackson.core.JacksonException
    • _deserializeFromString

      protected T _deserializeFromString(tools.jackson.core.JsonParser p, DeserializationContext ctxt) throws tools.jackson.core.JacksonException
      Helper method to call in case deserializer does not support native automatic use of incoming String values, but there may be standard coercions to consider.
      Throws:
      tools.jackson.core.JacksonException
      Since:
      2.12
    • _deserializeFromEmptyString

      protected Object _deserializeFromEmptyString(tools.jackson.core.JsonParser p, DeserializationContext ctxt, CoercionAction act, Class<?> rawTargetType, String desc) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • _deserializeWrappedValue

      protected T _deserializeWrappedValue(tools.jackson.core.JsonParser p, DeserializationContext ctxt) throws tools.jackson.core.JacksonException
      Helper called to support DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS: default implementation simply calls ValueDeserializer.deserialize(JsonParser, DeserializationContext), but handling may be overridden.
      Throws:
      tools.jackson.core.JacksonException
    • _parseBooleanPrimitive

      protected final boolean _parseBooleanPrimitive(tools.jackson.core.JsonParser p, DeserializationContext ctxt) throws tools.jackson.core.JacksonException
      Parameters:
      ctxt - Deserialization context for accessing configuration
      p - Underlying parser
      Throws:
      tools.jackson.core.JacksonException
    • _isTrue

      protected boolean _isTrue(String text)
    • _isFalse

      protected boolean _isFalse(String text)
    • _parseBoolean

      protected final Boolean _parseBoolean(tools.jackson.core.JsonParser p, DeserializationContext ctxt, Class<?> targetType) throws tools.jackson.core.JacksonException
      Helper method called for cases where non-primitive, boolean-based value is to be deserialized: result of this method will be Boolean, although actual target type may be something different.

      Note: does NOT dynamically access "empty value" or "null value" of deserializer since those values could be of type other than Boolean. Caller may need to translate from 3 possible result types into appropriately matching output types.

      Parameters:
      p - Underlying parser
      ctxt - Deserialization context for accessing configuration
      targetType - Actual type that is being deserialized, may be same as handledType() but could be AtomicBoolean for example. Used for coercion config access.
      Throws:
      tools.jackson.core.JacksonException
      Since:
      2.12
    • _parseBytePrimitive

      protected final byte _parseBytePrimitive(tools.jackson.core.JsonParser p, DeserializationContext ctxt) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • _parseShortPrimitive

      protected final short _parseShortPrimitive(tools.jackson.core.JsonParser p, DeserializationContext ctxt) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • _parseIntPrimitive

      protected final int _parseIntPrimitive(tools.jackson.core.JsonParser p, DeserializationContext ctxt) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • _parseIntPrimitive

      protected final int _parseIntPrimitive(tools.jackson.core.JsonParser p, DeserializationContext ctxt, String text) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • _parseInteger

      protected final Integer _parseInteger(tools.jackson.core.JsonParser p, DeserializationContext ctxt, Class<?> targetType) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
      Since:
      2.12
    • _parseInteger

      protected final Integer _parseInteger(tools.jackson.core.JsonParser p, DeserializationContext ctxt, String text)
    • _parseLongPrimitive

      protected final long _parseLongPrimitive(tools.jackson.core.JsonParser p, DeserializationContext ctxt) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • _parseLongPrimitive

      protected final long _parseLongPrimitive(tools.jackson.core.JsonParser p, DeserializationContext ctxt, String text) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • _parseLong

      protected final Long _parseLong(tools.jackson.core.JsonParser p, DeserializationContext ctxt, Class<?> targetType) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
      Since:
      2.12
    • _parseLong

      protected final Long _parseLong(DeserializationContext ctxt, String text)
    • _parseFloatPrimitive

      protected final float _parseFloatPrimitive(tools.jackson.core.JsonParser p, DeserializationContext ctxt) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • _parseFloatPrimitive

      protected final float _parseFloatPrimitive(tools.jackson.core.JsonParser p, DeserializationContext ctxt, String text) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • _checkFloatSpecialValue

      protected Float _checkFloatSpecialValue(String text)
      Helper method called to check whether given String value contains one of "special" values (currently, NaN ("not-a-number") and plus/minus Infinity) and if so, returns that value; otherwise returns null.
      Parameters:
      text - String value to check
      Returns:
      One of Float constants referring to special value decoded, if value matched; null otherwise.
    • _parseDoublePrimitive

      protected final double _parseDoublePrimitive(tools.jackson.core.JsonParser p, DeserializationContext ctxt) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • _parseDoublePrimitive

      protected final double _parseDoublePrimitive(tools.jackson.core.JsonParser p, DeserializationContext ctxt, String text) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • _parseDouble

      protected static final double _parseDouble(String numStr, boolean useFastParser) throws NumberFormatException
      Helper method for encapsulating calls to low-level double value parsing; single place just because we need a work-around that must be applied to all calls.
      Throws:
      NumberFormatException
    • _checkDoubleSpecialValue

      protected Double _checkDoubleSpecialValue(String text)
      Helper method called to check whether given String value contains one of "special" values (currently, NaN ("not-a-number") and plus/minus Infinity) and if so, returns that value; otherwise returns null.
      Parameters:
      text - String value to check
      Returns:
      One of Double constants referring to special value decoded, if value matched; null otherwise.
    • _parseDate

      protected Date _parseDate(tools.jackson.core.JsonParser p, DeserializationContext ctxt) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • _parseDateFromArray

      protected Date _parseDateFromArray(tools.jackson.core.JsonParser p, DeserializationContext ctxt) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • _parseDate

      protected Date _parseDate(String value, DeserializationContext ctxt) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
      Since:
      2.8
    • _parseString

      protected final String _parseString(tools.jackson.core.JsonParser p, DeserializationContext ctxt, NullValueProvider nullProvider) throws tools.jackson.core.JacksonException
      Helper method used for deserializing String value, if possible, doing necessary conversion or throwing exception as necessary.

      Will check CoercionConfig configuration to check whether coercion needed is allowed.

      Parameters:
      p - Currently active parser being iterated over
      ctxt - Deserialization context
      nullProvider - Entity we (only) need for case of secondary value type being coerced into null: if so, provider is asked for possible "null replacement" value.
      Throws:
      tools.jackson.core.JacksonException
    • _hasTextualNull

      protected boolean _hasTextualNull(String value)
      Helper method called to determine if we are seeing String value of "null", and, further, that it should be coerced to null just like null token.
    • _isNegInf

      protected final boolean _isNegInf(String text)
    • _isPosInf

      protected final boolean _isPosInf(String text)
    • _isNaN

      protected final boolean _isNaN(String text)
    • _isBlank

      protected static final boolean _isBlank(String text)
    • _checkFromStringCoercion

      protected CoercionAction _checkFromStringCoercion(DeserializationContext ctxt, String value) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • _checkFromStringCoercion

      protected CoercionAction _checkFromStringCoercion(DeserializationContext ctxt, String value, LogicalType logicalType, Class<?> rawTargetType) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • _checkFloatToIntCoercion

      protected CoercionAction _checkFloatToIntCoercion(tools.jackson.core.JsonParser p, DeserializationContext ctxt, Class<?> rawTargetType) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • _checkIntToStringCoercion

      protected CoercionAction _checkIntToStringCoercion(tools.jackson.core.JsonParser p, DeserializationContext ctxt, Class<?> rawTargetType) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • _checkFloatToStringCoercion

      protected CoercionAction _checkFloatToStringCoercion(tools.jackson.core.JsonParser p, DeserializationContext ctxt, Class<?> rawTargetType) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
      Since:
      2.14
    • _checkBooleanToStringCoercion

      protected CoercionAction _checkBooleanToStringCoercion(tools.jackson.core.JsonParser p, DeserializationContext ctxt, Class<?> rawTargetType) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
      Since:
      2.14
    • _checkToStringCoercion

      protected CoercionAction _checkToStringCoercion(tools.jackson.core.JsonParser p, DeserializationContext ctxt, Class<?> rawTargetType, Object inputValue, CoercionInputShape inputShape) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
      Since:
      2.14
    • _checkIntToFloatCoercion

      protected CoercionAction _checkIntToFloatCoercion(tools.jackson.core.JsonParser p, DeserializationContext ctxt, Class<?> rawTargetType) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • _coerceBooleanFromInt

      protected Boolean _coerceBooleanFromInt(tools.jackson.core.JsonParser p, DeserializationContext ctxt, Class<?> rawTargetType) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • _checkCoercionFail

      protected CoercionAction _checkCoercionFail(DeserializationContext ctxt, CoercionAction act, Class<?> targetType, Object inputValue, String inputDesc) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • _checkTextualNull

      protected boolean _checkTextualNull(DeserializationContext ctxt, String text)
      Method called when otherwise unrecognized String value is encountered for a non-primitive type: should see if it is String value "null", and if so, whether it is acceptable according to configuration or not
    • _coerceIntegral

      protected Object _coerceIntegral(tools.jackson.core.JsonParser p, DeserializationContext ctxt) throws tools.jackson.core.JacksonException
      Helper method called in case where an integral number is encountered, but config settings suggest that a coercion may be needed to "upgrade" Number into "bigger" type like Long or BigInteger
      Throws:
      tools.jackson.core.JacksonException
      Since:
      2.6
      See Also:
    • _verifyNullForPrimitive

      protected final void _verifyNullForPrimitive(DeserializationContext ctxt) throws DatabindException
      Method called to verify that null token from input is acceptable for primitive (unboxed) target type. It should NOT be called if null was received by other means (coerced due to configuration, or even from optionally acceptable String "null" token).
      Throws:
      DatabindException
    • _verifyNullForPrimitiveCoercion

      protected final void _verifyNullForPrimitiveCoercion(DeserializationContext ctxt, String str) throws DatabindException
      Method called to verify that text value "null" from input is acceptable for primitive (unboxed) target type. It should not be called if actual null token was received, or if null is a result of coercion from Some other input type.
      Throws:
      DatabindException
    • _reportFailedNullCoerce

      protected void _reportFailedNullCoerce(DeserializationContext ctxt, boolean state, Enum<?> feature, String inputDesc) throws DatabindException
      Throws:
      DatabindException
    • _coercedTypeDesc

      protected String _coercedTypeDesc()
      Helper method called to get a description of type into which a scalar value coercion is (most likely) being applied, to be used for constructing exception messages on coerce failure.
      Returns:
      Message with backtick-enclosed name of type this deserializer supports
    • _coercedTypeDesc

      protected String _coercedTypeDesc(Class<?> rawTargetType)
      Helper method called to get a description of type into which a scalar value coercion is being applied, to be used for constructing exception messages on coerce failure.
      Returns:
      Message with backtick-enclosed name of target type
      Since:
      2.15
    • findDeserializer

      protected ValueDeserializer<Object> findDeserializer(DeserializationContext ctxt, JavaType type, BeanProperty property)
      Helper method used to locate deserializers for properties the type this deserializer handles contains (usually for properties of bean types)
      Parameters:
      type - Type of property to deserialize
      property - Actual property object (field, method, constuctor parameter) used for passing deserialized values; provided so deserializer can be contextualized if necessary
    • _isIntNumber

      protected final boolean _isIntNumber(String text)
      Helper method to check whether given text refers to what looks like a clean simple integer number, consisting of optional sign followed by a sequence of digits.

      Note that definition is quite loose as leading zeroes are allowed, in addition to plus sign (not just minus).

    • findConvertingContentDeserializer

      protected ValueDeserializer<?> findConvertingContentDeserializer(DeserializationContext ctxt, BeanProperty prop, ValueDeserializer<?> existingDeserializer)
      Helper method that can be used to see if specified property has annotation indicating that a converter is to be used for contained values (contents of structured types; array/List/Map values)
      Parameters:
      existingDeserializer - (optional) configured content serializer if one already exists.
    • findFormatOverrides

      protected JsonFormat.Value findFormatOverrides(DeserializationContext ctxt, BeanProperty prop, Class<?> typeForDefaults)
      Helper method that may be used to find if this deserializer has specific JsonFormat settings, either via property, or through type-specific defaulting.
      Parameters:
      typeForDefaults - Type (erased) used for finding default format settings, if any
    • findFormatFeature

      protected Boolean findFormatFeature(DeserializationContext ctxt, BeanProperty prop, Class<?> typeForDefaults, JsonFormat.Feature feat)
      Convenience method that uses findFormatOverrides(tools.jackson.databind.DeserializationContext, tools.jackson.databind.BeanProperty, java.lang.Class<?>) to find possible defaults and/of overrides, and then calls JsonFormat.Value.getFeature(feat) to find whether that feature has been specifically marked as enabled or disabled.
      Parameters:
      typeForDefaults - Type (erased) used for finding default format settings, if any
    • findValueNullProvider

      protected final NullValueProvider findValueNullProvider(DeserializationContext ctxt, SettableBeanProperty prop, PropertyMetadata propMetadata)
      Method called to find NullValueProvider for a primary property, using "value nulls" setting. If no provider found (not defined, or is "skip"), will return `null`.
    • findContentNullProvider

      protected NullValueProvider findContentNullProvider(DeserializationContext ctxt, BeanProperty prop, ValueDeserializer<?> valueDeser)
      Method called to find NullValueProvider for a contents of a structured primary property (Collection, Map, array), using "content nulls" setting. If no provider found (not defined), will return given value deserializer (which is a null value provider itself).
    • findContentNullStyle

      protected Nulls findContentNullStyle(DeserializationContext ctxt, BeanProperty prop)
    • _findNullProvider

      protected final NullValueProvider _findNullProvider(DeserializationContext ctxt, BeanProperty prop, Nulls nulls, ValueDeserializer<?> valueDeser)
    • _findCoercionFromEmptyString

      protected CoercionAction _findCoercionFromEmptyString(DeserializationContext ctxt)
    • _findCoercionFromEmptyArray

      protected CoercionAction _findCoercionFromEmptyArray(DeserializationContext ctxt)
    • _findCoercionFromBlankString

      protected CoercionAction _findCoercionFromBlankString(DeserializationContext ctxt)
    • handleUnknownProperty

      protected void handleUnknownProperty(tools.jackson.core.JsonParser p, DeserializationContext ctxt, Object instanceOrClass, String propName) throws tools.jackson.core.JacksonException
      Method called to deal with a property that did not map to a known Bean property. Method can deal with the problem as it sees fit (ignore, throw exception); but if it does return, it has to skip the matching Json content parser has.
      Parameters:
      p - Parser that points to value of the unknown property
      ctxt - Context for deserialization; allows access to the parser, error reporting functionality
      instanceOrClass - Instance that is being populated by this deserializer, or if not known, Class that would be instantiated. If null, will assume type is what handledType() returns.
      propName - Name of the property that cannot be mapped
      Throws:
      tools.jackson.core.JacksonException
    • handleMissingEndArrayForSingle

      protected void handleMissingEndArrayForSingle(tools.jackson.core.JsonParser p, DeserializationContext ctxt) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • handleNestedArrayForSingle

      protected Object handleNestedArrayForSingle(tools.jackson.core.JsonParser p, DeserializationContext ctxt) throws tools.jackson.core.JacksonException
      Helper method called when detecting a deep(er) nesting of Arrays when trying to unwrap value for DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS.
      Throws:
      tools.jackson.core.JacksonException
      Since:
      2.14
    • _verifyEndArrayForSingle

      protected void _verifyEndArrayForSingle(tools.jackson.core.JsonParser p, DeserializationContext ctxt) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • _wrapIOFailure

      protected tools.jackson.core.JacksonException _wrapIOFailure(DeserializationContext ctxt, IOException e)
    • _neitherNull

      protected static final boolean _neitherNull(Object a, Object b)
    • _byteOverflow

      protected final boolean _byteOverflow(int value)
    • _shortOverflow

      protected final boolean _shortOverflow(int value)
    • _intOverflow

      protected final boolean _intOverflow(long value)
    • _nonNullNumber

      protected Number _nonNullNumber(Number n)