springboot返回json将null转为空字符串 作者:马育民 • 2021-10-11 10:31 • 阅读:10058 # 添加pom配置 ``` com.fasterxml.jackson.core jackson-databind 2.6.6 ``` # 配置类 ``` @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() { @Override public void serialize(Object o, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException { jsonGenerator.writeString(""); } }); return objectMapper; } } ``` 原文出处:http://malaoshi.top/show_1IX21MTjCplD.html