json序列化時,不序列化值為null和""的欄位
阿新 • • 發佈:2019-01-31
<!-- jackson --> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> <version>2.2.3</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.2.3</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-annotations</artifactId> <version>2.2.3</version> </dependency>
在類上新增@JsonInclude(Include.NON_EMPTY),在javabean to json的序列化過程中,將不序列化值為null或者為""的欄位
@JsonInclude(Include.NON_EMPTY)
public class EntityResponseResults extends BaseResponseResults {
/** 返回結果 */
private Object results;
}
另外,和@JsonInclude()的引數一共有四種:
Include.Include.ALWAYS 預設 Include.NON_DEFAULT 屬性為預設值不序列化 Include.NON_EMPTY 屬性為 空("") 或者為 null 都不序列化 Include.NON_NULL 屬性為NULL 不序列化