JAV实体类序列化将字段null返回空字符串

编程

/**

* 实体类序列化将字段null返回空字符串

* @author

*

*/

@Configuration

public class JacksonConfig {

@Bean

@Primary

@ConditionalOnMissingBean(ObjectMapper.class)

public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) {

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

SerializerProvider serializerProvider = objectMapper.getSerializerProvider();

serializerProvider.setNullValueSerializer(new JsonSerializer<Object>() {

@Override

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

jsonGenerator.writeString("");

}

});

return objectMapper;

}

}

 

以上是 JAV实体类序列化将字段null返回空字符串 的全部内容, 来源链接: utcz.com/z/511594.html

回到顶部