ObjectMapper配置
来源:互联网 发布:java泛型方法定义 编辑:程序博客网 时间:2024/06/03 20:56
JSON-to-Java mapping features
Simple On/off Features
Following on/off features are defined in DeserializationConfig.Feature (Jackson 1.x) orDeserializationFeature (Jackson 2.x), and include:
These can be grouped as follows:
Annotation processing
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 forAnnotationIntrospector 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.
- AUTO_DETECT_SETTERS(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
- 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.
- 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.
- 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.
Conversions
- USE_BIG_DECIMAL_FOR_FLOATS (default: false)
Controls whether java.math.BigDecimal is used for deserializingJSON floating point numbers, when resulting type is a generic type (java.lang.Object) or generic number type (java.lang.Number); if disabled type will bejava.lang.Double
Does not affect explicit type (i.e. if expected result type isjava.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, typejava.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 1.6)
Determines which method is used to determine expected serialization of an Enum: if false (default), useEnum.name(); if true, Enum.toString().
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 (default: false) (since 1.8)
- 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 1.9)
Determines whether to bind JSON Arrays as java.util.Lists orObject[] instances, when binding to nominal type of java.lang.Object: if disabled, asList, if enabled as Object[].
Failure handling
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)
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', aJsonProcessingException 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_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).
- ObjectMapper配置
- ObjectMapper
- ObjectMapper
- ObjectMapper
- spring jack 使用自定义的objectMapper。或者在xml配置objectMapper参数
- spring jack 使用自定义的objectMapper。或者在xml配置objectMapper参数
- Jackson - ObjectMapper
- ObjectMapper相关
- java ObjectMapper
- 摘抄的ObjectMapper用法
- Jackson ObjectMapper解析
- ObjectMapper读取转义字符
- ObjectMapper读取转义字符
- Jackson ObjectMapper类
- ObjectMapper 的一个坑
- objectmapper的转化问题
- SpringBoot 定制Jackson ObjectMapper
- ObjectMapper 简单使用
- 谷歌眼镜Mirror API Reference之标准化查询参数
- 使用google protobuf
- 杭电2005
- 月極體位度數
- Linux USB架构浅谈
- ObjectMapper配置
- 读书简录
- 系统架构师与项目经理、系统分析师的关系及区别
- 通过tomcat实现多域名配置
- 一次“峰回路转”的troubleshooting经历
- 如何调整 CComboBox 下拉列表的高度
- Centos 5.1系统,通过网络升级内核,支持xfs文件系统
- Spring security控制权限的几种方法
- 使用事务批量导入数据