com.fasterxml.jackson.databind

Enum DeserializationFeature

  • All Implemented Interfaces:
    ConfigFeature, Serializable, Comparable<DeserializationFeature>


    public enum DeserializationFeature
    extends Enum<DeserializationFeature>
    implements ConfigFeature
    Enumeration that defines simple on/off features that affect the way Java objects are deserialized from JSON

    Note that features can be set both through ObjectMapper (as sort of defaults) and through ObjectReader. In first case these defaults must follow "config-then-use" patterns (i.e. defined once, not changed afterwards); all per-call changes must be done using ObjectReader.

    Note that features that do not indicate version of inclusion were available in Jackson 2.0 (or earlier); only later additions indicate version of inclusion.

    • Enum Constant Detail

      • USE_BIG_DECIMAL_FOR_FLOATS

        public static final DeserializationFeature USE_BIG_DECIMAL_FOR_FLOATS
        Feature that determines whether JSON floating point numbers are to be deserialized into BigDecimals if only generic type description (either Object or Number, or within untyped Map or Collection context) is available. If enabled such values will be deserialized as BigDecimals; if disabled, will be deserialized as Doubles.

        Feature is disabled by default, meaning that "untyped" floating point numbers will by default be deserialized as Doubles (choice is for performance reason -- BigDecimals are slower than Doubles).

      • USE_BIG_INTEGER_FOR_INTS

        public static final DeserializationFeature USE_BIG_INTEGER_FOR_INTS
        Feature that determines whether JSON integral (non-floating-point) numbers are to be deserialized into BigIntegers if only generic type description (either Object or Number, or within untyped Map or Collection context) is available. If enabled such values will be deserialized as BigIntegers; if disabled, will be deserialized as "smallest" available type, which is either Integer, Long or BigInteger, depending on number of digits.

        Feature is disabled by default, meaning that "untyped" floating point numbers will by default be deserialized using whatever is the most compact integral type, to optimize efficiency.

      • USE_JAVA_ARRAY_FOR_JSON_ARRAY

        public static final DeserializationFeature USE_JAVA_ARRAY_FOR_JSON_ARRAY
        Feature that determines whether JSON Array is mapped to Object[] or List<Object> when binding "untyped" objects (ones with nominal type of java.lang.Object). If true, binds as Object[]; if false, as List<Object>.

        Feature is disabled by default, meaning that JSON arrays are bound as Lists.

      • READ_ENUMS_USING_TO_STRING

        public static final DeserializationFeature READ_ENUMS_USING_TO_STRING
        Feature that determines standard deserialization mechanism used for Enum values: if enabled, Enums are assumed to have been serialized using return value of Enum.toString(); if disabled, return value of Enum.name() is assumed to have been used.

        Note: this feature should usually have same value as SerializationFeature.WRITE_ENUMS_USING_TO_STRING.

        Feature is disabled by default.

      • FAIL_ON_UNKNOWN_PROPERTIES

        public static final DeserializationFeature FAIL_ON_UNKNOWN_PROPERTIES
        Feature that determines whether encountering of unknown properties (ones that do not map to a property, and there is no "any setter" or handler that can handle it) should result in a failure (by throwing a JsonMappingException) or not. This setting only takes effect after all other handling methods for unknown properties have been tried, and property remains unhandled.

        Feature is enabled by default (meaning that a JsonMappingException will be thrown if an unknown property is encountered).

      • FAIL_ON_NULL_FOR_PRIMITIVES

        public static final DeserializationFeature FAIL_ON_NULL_FOR_PRIMITIVES
        Feature that determines whether encountering of JSON null is an error when deserializing into Java primitive types (like 'int' or 'double'). If it is, a JsonProcessingException is thrown to indicate this; if not, default value is used (0 for 'int', 0.0 for double, same defaulting as what JVM uses).

        Feature is disabled by default.

      • FAIL_ON_NUMBERS_FOR_ENUMS

        public static final DeserializationFeature FAIL_ON_NUMBERS_FOR_ENUMS
        Feature that determines whether JSON integer numbers are valid values to be used for deserializing Java enum values. If set to 'false' numbers are acceptable and are used to map to ordinal() of matching enumeration value; if 'true', numbers are not allowed and a JsonMappingException will be thrown. Latter behavior makes sense if there is concern that accidental mapping from integer values to enums might happen (and when enums are always serialized as JSON Strings)

        Feature is disabled by default.

      • FAIL_ON_INVALID_SUBTYPE

        public static final DeserializationFeature FAIL_ON_INVALID_SUBTYPE
        Feature that determines what happens when type of a polymorphic value (indicated for example by JsonTypeInfo) can not be found (missing) or resolved (invalid class name, unmappable id); if enabled, an exception ir thrown; if false, null value is used instead.

        Feature is enabled by default so that exception is thrown for missing or invalid type information.

        Since:
        2.2
      • FAIL_ON_READING_DUP_TREE_KEY

        public static final DeserializationFeature FAIL_ON_READING_DUP_TREE_KEY
        Feature that determines what happens when reading JSON content into tree (TreeNode) and a duplicate key is encountered (property name that was already seen for the JSON Object). If enabled, JsonMappingException will be thrown; if disabled, no exception is thrown and the new (later) value overwrites the earlier value.

        Note that this property does NOT affect other aspects of data-binding; that is, no detection is done with respect to POJO properties or Map keys. New features may be added to control additional cases.

        Feature is disabled by default so that no exception is thrown.

        Since:
        2.3
      • FAIL_ON_IGNORED_PROPERTIES

        public static final DeserializationFeature FAIL_ON_IGNORED_PROPERTIES
        Feature that determines what happens when a property that has been explicitly marked as ignorable is encountered in input: if feature is enabled, JsonMappingException is thrown; if false, property is quietly skipped.

        Feature is disabled by default so that no exception is thrown.

        Since:
        2.3
      • WRAP_EXCEPTIONS

        public static final DeserializationFeature WRAP_EXCEPTIONS
        Feature that determines whether Jackson code should catch and wrap Exceptions (but never Errors!) to add additional information about location (within input) of problem or not. If enabled, most exceptions will be caught and re-thrown (exception specifically being that IOExceptions may be passed as is, since they are declared as throwable); this can be convenient both in that all exceptions will be checked and declared, and so there is more contextual information. However, sometimes calling application may just want "raw" unchecked exceptions passed as is.

        Feature is enabled by default.

      • ACCEPT_SINGLE_VALUE_AS_ARRAY

        public static final DeserializationFeature ACCEPT_SINGLE_VALUE_AS_ARRAY
        Feature that determines whether it is acceptable to coerce non-array (in JSON) values to work with Java collection (arrays, java.util.Collection) types. If enabled, collection deserializers will try to handle non-array values as if they had "implicit" surrounding JSON array. This feature is meant to be used for compatibility/interoperability reasons, to work with packages (such as XML-to-JSON converters) that leave out JSON array in cases where there is just a single element in array.

        Feature is disabled by default.

      • UNWRAP_SINGLE_VALUE_ARRAYS

        public static final DeserializationFeature UNWRAP_SINGLE_VALUE_ARRAYS
        Feature that determines whether it is acceptable to coerce single value array (in JSON) values to the corresponding value type. This is basically the opposite of the ACCEPT_SINGLE_VALUE_AS_ARRAY feature. If more than one value is found in the array, a JsonMappingException is thrown.

        Feature is disabled by default

        Since:
        2.4
      • UNWRAP_ROOT_VALUE

        public static final DeserializationFeature UNWRAP_ROOT_VALUE
        Feature to allow "unwrapping" root-level JSON value, to match setting of SerializationFeature.WRAP_ROOT_VALUE used for serialization. Will verify that the root JSON value is a JSON Object, and that it has a single property with expected root name. If not, a JsonMappingException is thrown; otherwise value of the wrapped property will be deserialized as if it was the root value.

        Feature is disabled by default.

      • ACCEPT_EMPTY_STRING_AS_NULL_OBJECT

        public static final DeserializationFeature ACCEPT_EMPTY_STRING_AS_NULL_OBJECT
        Feature that can be enabled to allow JSON empty String value ("") to be bound to POJOs as null. If disabled, standard POJOs can only be bound from JSON null or JSON Object (standard meaning that no custom deserializers or constructors are defined; both of which can add support for other kinds of JSON values); if enable, empty JSON String can be taken to be equivalent of JSON null.

        Feature is enabled by default.

      • READ_UNKNOWN_ENUM_VALUES_AS_NULL

        public static final DeserializationFeature READ_UNKNOWN_ENUM_VALUES_AS_NULL
        Feature that allows unknown Enum values to be parsed as null values. If disabled, unknown Enum values will throw exceptions.

        Note that in some cases this will basically ignore unknown Enum values; this is the keys for keys of EnumMap and values of EnumSet (because nulls are not accepted in these cases).

        Feature is disabled by default.

        Since:
        2.0
      • READ_DATE_TIMESTAMPS_AS_NANOSECONDS

        public static final DeserializationFeature READ_DATE_TIMESTAMPS_AS_NANOSECONDS
        Feature that controls whether numeric timestamp values are expected to be written using nanosecond timestamps (enabled) or not (disabled), if and only if datatype supports such resolution. Only newer datatypes (such as Java8 Date/Time) support such resolution -- older types (pre-Java8 java.util.Date etc) and Joda do not -- and this setting has no effect on such types.

        If disabled, standard millisecond timestamps are assumed. This is the counterpart to SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS.

        Feature is enabled by default, to support most accurate time values possible.

        Since:
        2.2
      • ADJUST_DATES_TO_CONTEXT_TIME_ZONE

        public static final DeserializationFeature ADJUST_DATES_TO_CONTEXT_TIME_ZONE
        Feature that specifies whether context provided TimeZone (DeserializationContext.getTimeZone() should be used to adjust Date/Time values on deserialization, even if value itself contains timezone information. If enabled, contextual TimeZone will essentially override any other TimeZone information; if disabled, it will only be used if value itself does not contain any TimeZone information.
        Since:
        2.2
      • EAGER_DESERIALIZER_FETCH

        public static final DeserializationFeature EAGER_DESERIALIZER_FETCH
        Feature that determines whether ObjectReader should try to eagerly fetch necessary JsonDeserializer when possible. This improves performance in cases where similarly configured ObjectReader instance is used multiple times; and should not significantly affect single-use cases.

        Note that there should not be any need to normally disable this feature: only consider that if there are actual perceived problems.

        Feature is enabled by default.

        Since:
        2.1
    • Method Detail

      • values

        public static DeserializationFeature[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (DeserializationFeature c : DeserializationFeature.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static DeserializationFeature valueOf(String name)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
        Parameters:
        name - the name of the enum constant to be returned.
        Returns:
        the enum constant with the specified name
        Throws:
        IllegalArgumentException - if this enum type has no constant with the specified name
        NullPointerException - if the argument is null
      • enabledByDefault

        public boolean enabledByDefault()
        Description copied from interface: ConfigFeature
        Accessor for checking whether this feature is enabled by default.
        Specified by:
        enabledByDefault in interface ConfigFeature
      • getMask

        public int getMask()
        Description copied from interface: ConfigFeature
        Returns bit mask for this feature instance
        Specified by:
        getMask in interface ConfigFeature

Copyright © 2014 FasterXML. All Rights Reserved.