Jackson - Features for configuring Java-to-JSON mapping
Following on/off features are defined in SerializationConfig.Feature (for Jackson 1.x), or SerializationFeature (Jackson 2.x):
AUTO_DETECT_FIELDS (default: true)
Feature that determines whether non-static fields are recognized as properties. If yes, then all public member fields are considered as properties. If disabled, only fields explicitly annotated are considered property fields.
Note that this feature has lower precedence than per-class annotations, and is only used if there isn't more granular configuration available.
AUTO_DETECT_GETTERS (default: true)
Controls whether "getter" methods are automatically detected (as opposed to located by annotations); if enabled, public no-argument non-static no-argument methods are recognized as getters. If disabled, only ones explicitly annotated (using @JsonProperty, for example) are recognized as serializable properties
AUTO_DETECT_IS_GETTERS (default: true)
Controls whether "is-getter" methods (methods with name "isXxx()" that return boolean or java.lang.Boolean value) are automatically detected (as opposed to located by annotations); if enabled, such methods are detected as getters. If disabled, only ones explicitly annotated (using @JsonProperty, for example) are recognized as serializable 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.
CLOSE_CLOSEABLE (default: false) (since 1.6)
If enabled, ObjectMapper will call close() and root values that implement java.io.Closeable; including cases where exception is thrown and serialization does not completely succeed.
Can be useful for resource clean up; and specifically allows for building wrappers that can be useful when serializing referential values (like, say, serializing a java.io.File value by reading contents of a file and outputting as JSON String or base64-encoded binary)
DEFAULT_VIEW_INCLUSION (default: true) (since 1.5)
Controls what is the behavior of properties that have no matching JsonView annotation: if set to true, they are included in all views; if false, not included in any views. This only affects JSON View enabled processing (i.e. when Serialization View is specified)
FAIL_ON_EMPTY_BEANS (default: true) (since 1.4)
Controls whether exception is thrown if no serializer is found for a type (Class); and type has neither getters nor recognized annotations (ones configured AnnotationIntrospector recognizes, including JacksonJAXBAnnotations if JAXB introspector used). If enabled, exception is thrown; if disabled, will just output empty JSON Object.
FLUSH_AFTER_WRITE_VALUE (default: true) (since 1.7)
Determines whether JsonGenerator.flush() is automatically called after ObjectMapper's writeValue(JsonGenerator, ...) is called or not (note: does NOT affect methods that do not take JsonGenerator) -- if true flush() is called; if false, it is not called.
Main reason to disable this feature is performance; for network connections flushing may send message earlier than optimal, and with some compressing streams compression block may complete with flush().
INDENT_OUTPUT (default: false)
Controls whether output is indented using the default indentation ("pretty-printing") mechanism (2-space, platform linefeeds) or not.
REQUIRE_SETTERS_FOR_GETTERS (default: false)
Controls whether auto-detection of getter methods requires presence of mutators (setter / constructor argument / field) to include auto-detectable getters or not: if enabled, only getters with matching mutator are included via auto-detection (meaning: explicitly annotated getters are still included); if disabled, all auto-detectable getters are included.
NOTE: some frameworks such as JAXB behave as if this feature was enabled; and enabling it can help ensure that serialized JSON can be deserialized back -- conversely, for write-only use cases, this feature is usually best left disabled.
SORT_PROPERTIES_ALPHABETICALLY (default: false) (since 1.8)
Controls default ordering used for serializing POJO fields (note: does NOT apply to Maps!): if enabled, default ordering is alphabetic (similar to how @JsonPropertyOrder.alphabetic=true works; if disabled, default order is unspecified.
Note that explicit ordering annotations on type (class) override default settings.
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_STATIC_TYPING (default: false)
Controls whether the type detection for serialization should be using actual dynamic runtime type or declared static type. Default value is false, to use dynamic runtime type.
This global default value can be overridden at class, or method/field level by using JsonSerialize annotation (its typing property)
WRAP_ROOT_Exception (default: false) (since 1.7)
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.
WRAP_ROOT_VALUE (default: false) (since 1.7)
When enabled, will wrap output in a single-property JSON Object. Name of wrapper property is based on class name of the serialized instance (or value type if static typing used or root type specified); or, if using JAXB annotations, name from @XmlRootElement.
WRITE_BIGDECIMAL_AS_PLAIN (default: false) (since 2.2)
If enabled, will prevent use of scientific notation (use of 'e' in value to normalize scale of mantisaa); if disabled, will use scientific notation when necessary.
WRITE_CHAR_ARRAYS_AS_JSON_ARRAYS (default: false) (since 1.6)
Controls how basic char[] values are serialized: if enabled, they will be serialized as full JSON Arrays, with JSON Strings (of length 1 character) as elements; if disabled (which is the default) as a single JSON String consisting of all characters of the array.
WRITE_DATES_AS_TIMESTAMPS (default: true)
Controls whether Date / Time values are to be written out as numeric (64-bit) timestamps (if true) or as Strings. If latter, format used is defined by SerializationConfig.getDateFormat
WRITE_DATE_KEY_AS_TIMESTAMPS (default: false)
Feature that determines whether Dates (and sub-types) used as Map keys are serialized as timestamps or not (if not, will be serialized as textual values).
Default value is 'false', meaning that Date-valued Map keys are serialized as textual (ISO-8601) values.
WRITE_EMPTY_JSON_ARRAYS (default: true) (since 1.9)
to allow suppressing serialization of empty Collections/arrays.
WRITE_ENUMS_USING_INDEX (default: false) (since 1.9)
Determines whether Enums are to be serialized as integers (true), or Strings (false): if integers, Enum.ordinal() value is used as serialization.
WRITE_ENUMS_USING_TO_STRING (default: false) (since 1.6)
Determines which method is used to determine expected serialization of an Enum (when serialized as String): if false (default), use Enum.name(); if true, Enum.toString().
WRITE_NULL_MAP_VALUES (default: true) (since 1.6)
Determines whether Map entries with value null are serialized or not.
WRITE_NULL_PROPERTIES (default: true) (NOTE: deprecated as of 1.1)
Controls where values of properties that have null as value are written out or not.
deprecated Use SerializationConfig#setSerializationInclusion instead
WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED (default: true) (since 2.0)
to change handling of single-element Arrays, java.util.Collections, so that such arrays/collections are serialized as "unwrapped" elements, not as JSON Arrays.
Jackson - Features for configuring Java-to-JSON mapping的更多相关文章
- Java之JSON操作(Jackson)
Java to JSON: package json.jackson; import bean.User; import com.fasterxml.jackson.databind.ObjectMa ...
- Java解析json(二):jackson
Java解析json(二):jackson 官方参考 Jackson Home Page:https://github.com/FasterXML/jackson Jackson Wiki:htt ...
- Java操作JSON数据(4,end)--Jackson操作JSON数据
Jackson是SpringBoot默认使用的JSON处理库,它可以轻松的将Java对象转换成JSON对象,同样也可以将JSON转换成Java对象.本文介绍下Jackson的基本使用方法,包括序列化和 ...
- Java JWT: JSON Web Token
Java JWT: JSON Web Token for Java and Android JJWT aims to be the easiest to use and understand libr ...
- Jackson 通过自定义注解来控制json key的格式
Jackson 通过自定义注解来控制json key的格式 最近我这边有一个需求就是需要把Bean中的某一些特殊字段的值进行替换.而这个替换过程是需要依赖一个第三方的dubbo服务的.为了使得这个转换 ...
- Java 的 JSON 开源类库选择比较(zz)
在看了作者的介绍,然后我又到mvnrepository上去看了各个库的的使用数之后,发现只能在jackson和gson之间做选择. 以下是原文 有效选择七个关于Java的JSON开源类库 April ...
- java系列--JSON数据的处理
http://blog.csdn.net/qh_java/article/details/38610599 http://www.cnblogs.com/lanxuezaipiao/archive/2 ...
- 使用jackson来进行数组格式的json字符串转换成List。
有一个字符串如下.如下,也是通过jackson把list转换成的json字符串,我想把它转过来,看网上的内容都不尽人如意,都是片断的内容.估计只有写的知道怎么使用,所以就直接看了jackson的官网, ...
- js处理json数据,java处理json数据
一.js处理json数据 处理办法之一是把本机json数据或远程返回json数据用eval函数,使之变成DOM对象. 例如: var people = { "programmers" ...
随机推荐
- UVaLive 7267 Mysterious Antiques in Sackler Museum (if-else,枚举)
题意:给定四个矩形,要求从中选出三个,能不能拼成一个矩形. 析:说到这个题,我还坑了队友一次,读题读错了,我直接看的样例,以为是四个能不能组成,然后我们三个就拼命想有什么简便方法,后来没办法了,直接暴 ...
- Simple guide to Java Message Service (JMS) using ActiveMQ
JMS let’s you send messages containing for example a String, array of bytes or a serializable Java o ...
- cocos2dx搭建开发环境
windows7 64位 搭建cocos2dx 版本开发环境 目前cocos2dx分为2.x版本和3.x版本,搭建环境稍有不同 先搭建3.1版本win32开发环境 相关准备: 注意:安装路径尽可能不要 ...
- Boost::Asio入门剖析
Boost::Asio可以在socket等I/O对象上执行同步或异步操作,使用Boost::Asio前很有必要了解Boost::Asio.你的程序以及它们交互的过程. 作为一个引导的例子,我们思考一个 ...
- Android Study ING
http://bbs.csdn.net/topics/370249613 android的tools和adb命令 http://www.u148.net/article/102147.html htt ...
- Android EditText载入HTML内容(内容包括网络图片)
android中的Html.fromHtml能够用来载入HTML的内容.fromHtml有三个參数须要设置,第一个是要显示的html内容,第二个就是要说的重点,ImageGetter,用来处理图片载入 ...
- esxi 5.1 由于断电错误无法启动 报错 bank5 invalid configuration
由于着急,处理过程中也没有截图,这里简单的描写叙述下整个过程吧. IBM pcserver x3850 可能是机器太热的原因,中午无故掉电,导致esxi无法正常启动 启动时报错 bank5 inval ...
- 理解 strcpy方法
char* strcpy(char* strDest, const char* strSrc) { assert((strDest!=NULL) && (strSrc !=NULL)) ...
- iOS开发——网络Swift篇&NSURLSession加载数据、下载、上传文件
NSURLSession加载数据.下载.上传文件 NSURLSession类支持三种类型的任务:加载数据.下载和上传.下面通过样例分别进行介绍. 1,使用Data Task加载数据 使用全局的 ...
- EasyBCD 2.2中文版安装变色龙wowpc.iso详细教程(适用各个版本)
第一章 安装变色龙引导本章节提供3种安装方案,请自行选择 1.使用 Windows 版变色龙安装器安装适用引导方案:BIOS+MBR第1步:下载 Chameleon Install 2.2svn228 ...