zoukankan      html  css  js  c++  java
  • Json返回结果为null属性不显示解决

    import java.io.IOException;
    
    import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.context.annotation.Primary;
    import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
    
    import com.fasterxml.jackson.core.JsonGenerator;
    import com.fasterxml.jackson.core.JsonProcessingException;
    import com.fasterxml.jackson.databind.JsonSerializer;
    import com.fasterxml.jackson.databind.ObjectMapper;
    import com.fasterxml.jackson.databind.SerializerProvider;
    
    @Configuration
    public class JacksonConfig {
        @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;
        }
    }
    

      0.0

  • 相关阅读:
    centos6.5下的mysql5.6.30安装
    mysql常见错误
    fpm打包redis3.0.7
    centos6.5安装fpm打包工具
    centos6.5安装flume
    centos6.5 安装mono
    利用rsyslog 对linux 操作进行审计
    CentOS7修改服务器主机名方法
    CentOS 7 修改网卡名称为eth
    keepalived配置日志
  • 原文地址:https://www.cnblogs.com/-flq/p/12012589.html
Copyright © 2011-2022 走看看