对于Spring Boot 1.2.3,如何在JSON序列化中设置ignore null值? [英] For Spring Boot 1.2.3, how to set ignore null value in JSON serialization?

查看:222
本文介绍了对于Spring Boot 1.2.3,如何在JSON序列化中设置ignore null值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In the Spring Boot 1.2.3, we can customize the Jackson ObjectMapper via properties file. But I didn't find a attribute can set Jackson ignore null value when serialization the Object to JSON string.

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.*=

我想归档相同的代码,如

I want to archive the same code like

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


推荐答案

这是Spring Boot 1.3.0的增强功能。

This was an enhancement for Spring Boot 1.3.0.

  • Support for spring.jackson.include
  • Add properties for Jackson serializationInclusion

所以不幸的是你需要以编程方式配置它on 1.2.3

So unfortunately you'll need to configure it programmatically on 1.2.3

@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
public class Shop {
    //...
}

这篇关于对于Spring Boot 1.2.3,如何在JSON序列化中设置ignore null值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆