美文网首页
com.fasterxml.jackson.core.jacks

com.fasterxml.jackson.core.jacks

作者: 青丝如梦 | 来源:发表于2018-12-29 10:38 被阅读0次

官网:https://github.com/FasterXML/jackson-annotations

https://www.carryingcoder.com/2017/10/31/Jackson%E7%94%A8%E6%B3%95-%E8%BF%99%E4%B8%80%E7%AF%87%E5%B0%B1%E5%A4%9F%E4%BA%86/

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;

相关文章

网友评论

      本文标题:com.fasterxml.jackson.core.jacks

      本文链接:https://www.haomeiwen.com/subject/eloelqtx.html