jackson
//序列化时转换为指定的属性
@JsonProperty(value = "UserID")
private Integer userID;
//序列化成为json的时候忽略此字段
@JsonIgnore
private String passWord;
//序列化成为json的时候指定日期格式,指定时区
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
private Date createTime;
//值为空时序列化是忽略此字段
@JsonInclude(JsonInclude.Include.NON_NULL)
private String description;
//输出时不自动转换为首字母小写
@JsonAutoDetect(fieldVisibility=JsonAutoDetect.Visibility.ANY, getterVisibility=JsonAutoDetect.Visibility.NONE)
private static ObjectMapper objectMapper;
public static ObjectMapper CreateInstance() {
if (objectMapper == null) {
objectMapper = new ObjectMapper();
}
//序列化时过滤为null的属性
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
//序列化时过滤为null和“”的属性
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
//反序列化时忽略不存在的属性
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
//反序列化时忽略属性的大小写
objectMapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
return objectMapper;
}
第一次写博客,先这么记录下吧,以后学习过程中在慢慢补充