com.fasterxml.jackson.core.jacks
2018-12-29 本文已影响0人
青丝如梦
官网:https://github.com/FasterXML/jackson-annotations
https://juejin.im/post/5c4970c6e51d4551b7482487
maven依赖:
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.11.1</version>
</dependency>
用于忽略属性的注释
-
@JsonIgnoreProperties(ignoreUnknown=true) 忽略POJO中没有,但是JSON中存在的属性
-
@JsonInclude POJO上使用,忽略NULL字段
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class User implements Serializable {
private Integer id;
private String name;
private Integer age;
}
说明:
//默认
ALWAYS,
// 属性为NULL 不序列化
NON_NULL,
// Value that indicates that properties are included unless their value is: null "absent" value of a referential type (like Java 8 `Optional`, or {link java.utl.concurrent.atomic.AtomicReference}); that is, something that would not deference to a non-null value.
NON_ABSENT,
// 属性为 空("") 或者为 NULL 都不序列化
NON_EMPTY,
// 属性为默认值不序列化
NON_DEFAULT,
// Pseudo-value used to indicate that the higher-level defaults make sense, to avoid overriding inclusion value. For example, if returned for a property this would use defaults for the class that contains property, if any defined; and if none defined for that, then global serialization inclusion details.
USE_DEFAULTS;