小编典典

对于Spring Boot 1.2.3,如何在JSON序列化中设置忽略空值?

spring-boot

在Spring Boot 1.2.3中,我们可以通过属性文件来自定义Jackson
Jackson。但是我没有找到将Object序列化为JSON字符串时可以设置Jackson忽略null值的属性。

spring.jackson.deserialization.*= # see Jackson's DeserializationFeature
spring.jackson.generator.*= # see Jackson's JsonGenerator.Feature
spring.jackson.mapper.*= # see Jackson's MapperFeature
spring.jackson.parser.*= # see Jackson's JsonParser.Feature
spring.jackson.serialization.*=

我想将相同的代码存档

ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(Include.NON_NULL);

阅读 627

收藏
2020-05-30

共1个答案

小编典典

这是对Spring Boot 1.3.0的增强。

因此,不幸的是,您需要在1.2.3上以编程方式对其进行配置

@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
public class Shop {
    //...
}
2020-05-30