阅读完需:约 1 分钟
fastjson
号称处理json最快的,但是它和gson
和jackson
不一样的是,fastjson
在springboot里面没有自动化配置,也就是说无论是springMVC还是springboot还是普通的java文件里都需要自己去装配它。
首先清楚springboot里默认的jackson
,再添加fastjson
依赖:

然后自己配置参数:
@Configuration
public class WebMvcController {
@Bean
FastJsonHttpMessageConverter fastJsonHttpMessageConverter(){
FastJsonHttpMessageConverter converter=new FastJsonHttpMessageConverter();
FastJsonConfig config=new FastJsonConfig();
config.setDateFormat("yyyy/MM/dd");
converter.setFastJsonConfig(config);
return converter;
}
}
最最关键的还是:FastJsonHttpMessageConverter
,我们可以在里面写更多的配置。
结果:

详细的配置(除了使用fastjson之外其他都一样):