Features for configuring JSON-to-Java mapping
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[].
Features for configuring JSON-to-Java mapping的更多相关文章
- 快速掌握Ajax-Ajax基础实例(Ajax返回Json在Java中的实现)
(转)实例二:Ajax返回Json在Java中的实现 转自http://www.cnblogs.com/lsnproj/archive/2012/02/09/2341524.html#2995114 ...
- Jsonschema2pojo从JSON生成Java类(命令行)
1.说明 jsonschema2pojo工具可以从JSON Schema(或示例JSON文件)生成Java类型, 在文章Jsonschema2pojo从JSON生成Java类(Maven) 已经介绍过 ...
- JSONObject.fromObject(map)(JSON与JAVA数据的转换)
JSON与JAVA数据的转换(JSON 即 JavaScript Object Natation,它是一种轻量级的数据交换格式,非常适合于服务器与 JavaScript 的交互.) 上一篇文章中有这么 ...
- json学习系列(8)JSON与JAVA数据的相互转换实例
一.完整案例 先定义一个java实体对象,如下: package com.pcitc.json.cnblog; /** * SimInfo实体对象 * * @Description * @author ...
- JSON 与JAVA对象之间的转换(转)
JSON与XML两者目前在数据交互方面都有很高的使用率,随着现在SOA的兴起,异构系统的整合地位相应提高,本篇文章主要介绍JSON与JAVA对象之间的相互转换. 一.对普通类型的JSON模式的转换 一 ...
- net.sf.json.JSONException: java.lang.NoSuchMethodException
在尝试将json对象转换为list时候出现了如下错误 Exception in thread "main" net.sf.json.JSONException: java.lang ...
- JSON与JAVA数据的相互转换
http://www.cnblogs.com/linjiqin/archive/2011/09/19/2181408.html import net.sf.json.JSONArray; import ...
- JSON和JAVA的POJO的相互转换【转载】
该类中用用到的jar包:参加文章<使用json-lib进行Java和JSON之间的转换[转载]> import java.util.Collection; import java.util ...
- json解析异常 - net.sf.json.JSONException: java.lang.reflect.InvocationTargetException
注:在项目中, 我使用原生的ajax请求数据的时候, JSONObject没能帮我解析, 当却不给我报错, 我是在junit单元测试中测试的时候, 发现的.发现好多时候, 特别是通过ajax请求, 不 ...
- 介绍4款json的java类库 及 其性能测试
JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式. 易于人阅读和编写.同时也易于机器解析和生成. 它基于JavaScript Programming Lan ...
随机推荐
- Linux下的进程管理
在操作系统系统中,进程是一个非常重要的概念. 一.Linux中进程的相关知识 1.什么是进程呢? 通俗的来说进程是运行起来的程序.唯一标示进程的是进程描述符(PID),在linux内核中是通过task ...
- 模拟学信网登录,Cookie 序列化,在反序列化之后不能用的问题
昨天和今天在模拟学信网登录,然后抓取用户的信息数据的时候发现一直登录不成功, 登录页面,https://account.chsi.com.cn/passport/login?service=http% ...
- Centos6.3 jekyll环境安装
yum install ruby yum install rubygems yum install ruby-devel gem install rdiscount yum install pytho ...
- JQuery的Ajax使用Get,Post方法调用C#WebService并返回数据
本文将介绍jQuery调用基于.NET Framework 3.5的WebService返回JSON数据,另外还要介绍一下用jQuery调用WebService的参数设置及设置不当所出现的问题,还有出 ...
- Apache Httpd通过mod_jk连接多个Tomcat
一个tomcat能够配置多个web apps,这是众所周知的.当更改了一个web app,想要又一次启动的时候.因为全部的web apps都是放在同一个tomcat下的,所以别的web apps也在重 ...
- javascript常见编程模式举例
近期买到手了一本<javascript框架设计>,具体介绍开发js框架所用到的知识.初读一点,乐帝脆弱的理论修养就暴露无遗了,所以专门加强理论修养,重看javascript编程模式的举例. ...
- memcpy的用法总结
1.memcpy 函数用于 把资源内存(src所指向的内存区域) 拷贝到目标内存(dest所指向的内存区域):拷贝多少个?有一个size变量控制拷贝的字节数:函数原型:void *memcpy(voi ...
- replace和insert的语句插入(转)
SELECT INTO 和 INSERT INTO SELECT 两种表复制语句 Insert是T-sql中常用语句,Insert INTO table(field1,field2,...) valu ...
- [Effective C++ --032]确定你的public继承塑模出is-a
这一章都在讲述继承的关系.可以举个例子说明: 父类是水果,子类是苹果,苹果是一种(is-a)水果,但是水果不一定就是苹果. is-a并不是唯一存在classes之间的关系.另两个常见的关系是has-a ...
- 第1章 游戏之乐——NIM(2)“拈”游戏分析
NIM(2)“拈”游戏分析 1. 问题 有N块石头和两个玩家A和B,玩家A先将石头分成若干堆,然后按照BABA……的顺序不断轮流取石头,能将剩下的石头一次取光的玩家获胜.每次取石头时,每个玩家只能从若 ...