json序列化时,不序列化值为null和""的字段

  
<dependency>  
    <groupId>com.fasterxml.jackson.coregroupId>  
    <artifactId>jackson-coreartifactId>  
    <version>2.2.3version>  
dependency>  
<dependency>  
    <groupId>com.fasterxml.jackson.coregroupId>  
    <artifactId>jackson-databindartifactId>  
    <version>2.2.3version>  
dependency>  
<dependency>  
    <groupId>com.fasterxml.jackson.coregroupId>  
    <artifactId>jackson-annotationsartifactId>  
    <version>2.2.3version>  
dependency>  

在类上添加@JsonInclude(Include.NON_EMPTY),在javabean to json的序列化过程中,将不序列化值为null或者为”“的字段

@JsonInclude(JsonInclude.Include.NON_NULL)
public class ResponseMetaPojo implements Serializable {
}

另外,和@JsonInclude()的参数一共有四种:

Include.Include.ALWAYS 默认   
Include.NON_DEFAULT 属性为默认值不序列化   
Include.NON_EMPTY 属性为 空("") 或者为 null 都不序列化   
Include.NON_NULL 属性为NULL 不序列化  

你可能感兴趣的:(json)