gpt4 book ai didi

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

转载 作者:IT老高 更新时间:2023-10-28 13:51:06 25 4
gpt4 key购买 nike

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

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);

最佳答案

将以下行添加到您的 application.properties 文件中。

spring.jackson.default-property-inclusion=non_null

对于 Jackson 2.7 之前的版本:

spring.jackson.serialization-inclusion=non_null

关于spring - 对于 Spring Boot 1.2.3,如何在 JSON 序列化中设置忽略 null 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30042507/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com