Spring boot 中 使用 Jackson 將null 欄位轉換為空字串寫法
阿新 • • 發佈:2019-02-16
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.add(new MappingJackson2HttpMessageConverter(objectMapper()));
super.configureMessageConverters(converters);
}
@Bean
@Primary
public ObjectMapper objectMapper(){
MyJackson2Object builder = new MyJackson2Object();
builder.propertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
builder.indentOutput(true).dateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));// 設定時間格式化
// converters.add(new MappingJackson2XmlHttpMessageConverter(builder.createXmlMapper(true).build()));
return builder.build();
}