Jackson 通过配置 JsonBinder ,来确定需要转化的JSON对象,
在Spring 配置
org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
/**
* 创建输出全部属性到Json字符串的Binder.
*/
public static JsonBinder buildNormalBinder() {
return new JsonBinder(Inclusion.ALWAYS);
}
/**
* 创建只输出非空属性到Json字符串的Binder.
*/
public static JsonBinder buildNonNullBinder() {
return new JsonBinder(Inclusion.NON_NULL);
}
/**
* 创建只输出初始值被改变的属性到Json字符串的Binder.
*/
public static JsonBinder buildNonDefaultBinder() {
return new JsonBinder(Inclusion.NON_DEFAULT);
}利用Jackson对Object,Map,List,数组,枚举,日期类等转化为json
原文:http://2197028.blog.51cto.com/2187028/1633054