Spring Boot ObjectMapper 不返回 null 字段
Spring Boot About 453 words需求
在使用ObjectMapper
或正常Controller
返回时,过滤掉值为null
的字段。
代码
主要是objectMapper.setSerializationInclusion
设置为JsonInclude.Include.NON_NULL
。
@Configuration
public class ObjectMapperConfig {
@Bean
public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) {
ObjectMapper objectMapper = builder.createXmlMapper(false).build();
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
return objectMapper;
}
}
Views: 604 · Posted: 2024-04-05
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb/LiteNote扫描下方二维码关注公众号和小程序↓↓↓
Loading...