美文网首页
springboot json返回值null解决

springboot json返回值null解决

作者: weylan | 来源:发表于2018-05-30 09:07 被阅读69次

springboot 默认使用jackson解析,曾尝试更改默认解析为fastjson,但在集成某些框架时会有问题,
https://www.jianshu.com/p/0a2bf9165f68
根据官方文档,修改解析方式如下:

 @Bean
    public Jackson2ObjectMapperBuilderCustomizer customJackson() {
        return jacksonObjectMapperBuilder -> {
            jacksonObjectMapperBuilder.serializationInclusion(JsonInclude.Include.NON_NULL);
            jacksonObjectMapperBuilder.failOnUnknownProperties(false);
            jacksonObjectMapperBuilder.propertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
        };
    }

用配置文件的方法
在Spring的文档里面有(https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#howto-customize-the-jackson-objectmapper

相关文章

网友评论

      本文标题:springboot json返回值null解决

      本文链接:https://www.haomeiwen.com/subject/pnttsftx.html