fastjson配置序列化过滤转换


@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {

@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {

FastJsonHttpMessageConverter fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter();
FastJsonConfig fastJsonConfig = new FastJsonConfig();
fastJsonConfig.setSerializeFilters(new ValueFilter() {
@Override
public Object process(Object object, String name, Object value) {
if (value == null){
return "";
}
if (value instanceof Date){
return DateUtils.formatDate((Date) value,"yyyy-MM-dd hh:mm:ss");
}
return value;
}
});
fastJsonHttpMessageConverter.setFastJsonConfig(fastJsonConfig);
List<MediaType> mediaTypes = new ArrayList<>();
mediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
fastJsonHttpMessageConverter.setSupportedMediaTypes(mediaTypes);
converters.add(fastJsonHttpMessageConverter);

}
}

文章作者: 知己而知彼
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 知己而知彼 !
评论
  目录