-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Deserialization Features
Jackson defines a set of features that relate to deserialization (reading JSON into Java Objects), and that can be changed on per-call basis.
Settings can be divided in couple of loose categories, as follows.
-
USE_BIG_DECIMAL_FOR_FLOATS (default: false)
-
Controls whether {{{java.math.BigDecimal}}} is used for deserializing {{{JSON}}} floating point numbers, when resulting type is a generic type ({{{java.lang.Object}}}) or generic number type ({{{java.lang.Number}}}); if disabled type will be {{{java.lang.Double}}}
-
Does not affect explicit type (i.e. if expected result type is {{{java.lang.Double}}} or such)
-
USE_BIG_INTEGER_FOR_INTS (default: false)
-
Similar to {{{USE_BIG_DECIMAL_FOR_FLOATS}}}, but used when value to map is a JSON integer number (numeric value without decimal point). If enabled, type {{{java.math.BigInteger}}} is used for binding to generic types; if disabled, {{{java.lang.Integer}}} or {{{java.lang.Long}}} is used (smallest applicable type that can contain actual value)
-
READ_ENUMS_USING_TO_STRING (default: false) (since JacksonRelease16)
-
Determines which method is used to determine expected serialization of an Enum: if false (default), use {{{Enum.name()}}}; if true, {{{Enum.toString()}}}.
-
ACCEPT_EMPTY_STRING_AS_NULL_OBJECT (default: false) (since JacksonRelease18)
-
Determines whether empty JSON String value is accepted as null value for regular POJOs ("beans") with data-binding: this can be useful when dealing endpoints written in a language that has loose typing and may represent missing objects as Empty Strings.
-
ACCEPT_SINGLE_VALUE_AS_ARRAY (default: false) (since JacksonRelease18)
- Allows auto-conversion from non-JSON-array values to single-element arrays and Collections (adding implicit "array wrapper"): this is sometimes necessary for interoperability, as some libraries and frameworks omit JSON arrays when serializing single-element arrays.
-
USE_JAVA_ARRAY_FOR_JSON_ARRAY (default: false) (since JacksonRelease19)
-
Determines whether to bind JSON Arrays as {{{java.util.Lists}}} or {{{Object[]}}} instances, when binding to nominal type of {{{java.lang.Object}}}: if disabled, as {{{List}}}, if enabled as {{{Object[]}}}.
- FAIL_ON_UNKNOWN_PROPERTIES (default: true) (since JacksonRelease12)
- Used to control whether encountering of unknown properties (one for which there is no setter; and there is no fallback "any setter" method defined using {{{@JsonAnySetter}}} annotation) should result in a {{{JsonMappingException}}} (when enabled), or just quietly ignored (when disabled)
- FAIL_ON_NULL_FOR_PRIMITIVES (default: false) (since JacksonRelease17)
- Determines whether JSON null is acceptable for Java primitive types ({{{int}}}, {{{boolean}}}, {{{double}}} etc); if set to 'false', default value is used; if 'true', a {{{JsonProcessingException}}} will be thrown.
- FAIL_ON_NUMBERS_FOR_ENUMS (default: false) (since JacksonRelease17)
- Determines whether JSON integer numbers (0, 1, 2, ...) can be deserialized into Java Enum types; if set to 'false', this is legal and value is used to deserialize value that matches Enum.ordinal(); if 'true', trying to deserialize JSON number into Enum throws a {{{JsonProcessingException}}}
- FAIL_ON_INVALID_SUBTYPE (default: true) (since [[JacksonRelease22 | 2.2])
- Determines what happens when type information for polymorphic types (see
@JsonTypeInfo
) is either missing or invalid (unmappable); if enabled, exception is thrown; if disabled, null reference is used instead (as type can not be determined).