美文网首页
2018-12-18 springboot返回属性的值为null

2018-12-18 springboot返回属性的值为null

作者: HelloWide | 来源:发表于2018-12-22 12:15 被阅读0次

    @Configuration

    public class JsonConfig {

        @Bean

        @Primary

        @ConditionalOnMissingBean(ObjectMapper.class)

        public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) {

            ObjectMapper objectMapper = builder.createXmlMapper(false).build();

            objectMapper.getSerializerProvider().setNullValueSerializer(new JsonSerializer<Object>() {

                @Override

                public void serialize(Object o, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException {

                    jsonGenerator.writeString("");//""空字符串或其他字符

                }

            });

            return objectMapper;

        }

    }

    相关文章

      网友评论

          本文标题:2018-12-18 springboot返回属性的值为null

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