Features for configuring JSON-to-Java mapping
2016-06-29 15:18
549 查看
Following on/off features are defined in DeserializationConfig.Feature (Jackson 1.x) or DeserializationFeature (Jackson 2.x):
ACCEPT_EMPTY_STRING_AS_NULL_OBJECT (default: false) (since 1.8)
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
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.
AUTO_DETECT_CREATORS (default: true)
Controls whether potential creator methods (public single-argument constructors, public static methods that return instance of class itself (aka factory methods)) can be automatically detected without being annotated with @JsonCreator (or similar for alternate annotation introspector).
AUTO_DETECT_FIELDS (default: true)
Similar to AUTO_DETECT_SETTERS, controls whether public instance fields are recognized as deserializable properties.
AUTO_DETECT_SETTERS (default: true)
Controls whether "setter" methods are automatically detected (as opposed to located by annotations); if enabled, non-private single-argument non-static methods are recognized as setters (method used to set value of the logical property). If disabled, only ones explicitly annotated (using @JsonProperty, for example) are recognized as deserializable properties
CAN_OVERRIDE_ACCESS_MODIFIERS (default: true)
Whether non-public fields and methods can be forced accessible (using JDK provided methods or not): if disabled, non-public fields and methods can not be used for properties.
The main reason to disable this feature is if running on a security-restricted platform where trying to change access rights results in a runtime error.
FAIL_ON_INVALID_SUBTYPE (default: true) (since 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).
FAIL_ON_NULL_FOR_PRIMITIVES (default: false) (since 1.7)
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 1.7)
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_UNKNOWN_PROPERTIES (default: true) (since 1.2)
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)
READ_ENUMS_USING_TO_STRING (default: false) (since 1.6)
Determines which method is used to determine expected serialization of an Enum: if false (default), use Enum.name(); if true, Enum.toString().
USE_ANNOTATIONS (default: true) (since 1.2)
Controls whether any annotation introspection is used for configuring data binding: if disabled, all annotations are ignored (independent of setting for AnnotationIntrospector in use)
note: since 1.8, disable this feature will try to remove ALL annotation processing; this to help on platforms like Android, where trying to access unavailable annotation types (JAXB annotations for value types) can result in exception, even if not specifically looking for that annotation type.
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)
USE_GETTERS_AS_SETTERS (default: true)
Controls whether "getters" that return Collection or Map types can be used for "setting" values (same as how JAXB API works with XML), so that separate "setter" method is not needed.
Even if enabled, explicit "setter" method will have precedence over implicit getter-as-setter, if one exists.
USE_JAVA_ARRAY_FOR_JSON_ARRAY (default: false) (since 1.9)
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[].
ACCEPT_EMPTY_STRING_AS_NULL_OBJECT (default: false) (since 1.8)
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
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.
AUTO_DETECT_CREATORS (default: true)
Controls whether potential creator methods (public single-argument constructors, public static methods that return instance of class itself (aka factory methods)) can be automatically detected without being annotated with @JsonCreator (or similar for alternate annotation introspector).
AUTO_DETECT_FIELDS (default: true)
Similar to AUTO_DETECT_SETTERS, controls whether public instance fields are recognized as deserializable properties.
AUTO_DETECT_SETTERS (default: true)
Controls whether "setter" methods are automatically detected (as opposed to located by annotations); if enabled, non-private single-argument non-static methods are recognized as setters (method used to set value of the logical property). If disabled, only ones explicitly annotated (using @JsonProperty, for example) are recognized as deserializable properties
CAN_OVERRIDE_ACCESS_MODIFIERS (default: true)
Whether non-public fields and methods can be forced accessible (using JDK provided methods or not): if disabled, non-public fields and methods can not be used for properties.
The main reason to disable this feature is if running on a security-restricted platform where trying to change access rights results in a runtime error.
FAIL_ON_INVALID_SUBTYPE (default: true) (since 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).
FAIL_ON_NULL_FOR_PRIMITIVES (default: false) (since 1.7)
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 1.7)
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_UNKNOWN_PROPERTIES (default: true) (since 1.2)
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)
READ_ENUMS_USING_TO_STRING (default: false) (since 1.6)
Determines which method is used to determine expected serialization of an Enum: if false (default), use Enum.name(); if true, Enum.toString().
USE_ANNOTATIONS (default: true) (since 1.2)
Controls whether any annotation introspection is used for configuring data binding: if disabled, all annotations are ignored (independent of setting for AnnotationIntrospector in use)
note: since 1.8, disable this feature will try to remove ALL annotation processing; this to help on platforms like Android, where trying to access unavailable annotation types (JAXB annotations for value types) can result in exception, even if not specifically looking for that annotation type.
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)
USE_GETTERS_AS_SETTERS (default: true)
Controls whether "getters" that return Collection or Map types can be used for "setting" values (same as how JAXB API works with XML), so that separate "setter" method is not needed.
Even if enabled, explicit "setter" method will have precedence over implicit getter-as-setter, if one exists.
USE_JAVA_ARRAY_FOR_JSON_ARRAY (default: false) (since 1.9)
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[].
相关文章推荐
- iOS 时间戳 时间串 比较和转换
- [Android]消息分发使用EventBus
- Android6.0权限管理
- [iOS 拍照上传] 上传图片 旋转 + 压缩大小
- [置顶] 微信硬件蓝牙扫描绑定JSAPI发送数据
- Android的一些知识点
- iOS开发The Operation couldn't be completed.(LaunchServicesError error 0.)的解决方法
- Android学习笔记 (图片选择器的使用selector)
- WebView与Cookies 的问题
- Scala 中的 apply 和 update 方法[转]
- 微信分享自定义图片标题摘要-微信官方API
- 问题十:关于application.loadlevel和SceneManager.LoadScene调用后新场景会变暗的问题
- Android中的RecyclerView新组件初步上手指南
- iOS开发之AFNetworking 3.0.4使用
- iOS Instruments来检验你的app
- Android传感器——加速度传感器
- iOS中常用动画大集合
- UIWebView内存占用过高、崩溃、内存溢出
- salesforce 零基础学习(三十五) 通过Process Builder和Approval Processes锁定记录(Lock Record)
- iOS 提示框,为什么你应该使用 MBProgressHUD?