首先加入fastjson
com.alibaba
fastjson
1.2.56
在 Spring MVC 中集成 Fastjson
/**
* 在spring boot 2.x中,直接实现WebMvcConfigurer接口即可,得益于Java8中的默认方法,WebMvcConfigurerAdapter已经过时
* @author hutaishi@qq.com
* @date 2019/3/4
*/
@Configuration
public class MyWebMvcConfigurer implements WebMvcConfigurer {
/**
* 在 Spring MVC 中集成 FastJson
*/
public void configureMessageConverters(List> converters) {
FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
//自定义配置...
FastJsonConfig config = new FastJsonConfig();
config.setSerializerFeatures(WriteNullListAsEmpty,
WriteNullStringAsEmpty,
WriteNullNumberAsZero,
WriteNullBooleanAsFalse,
WriteMapNullValue);
//处理中文乱码问题
List fastMed