依赖
// 使用gradle
compile group: 'com.alibaba', name: 'fastjson', version: '1.2.47'
配置
@Configuration
public class ApplicationConfiguration implements WebMvcConfigurer{
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
// FastJsonHttpMessageConverter默认配置支持MediaType.ALL,这里只支持允许MediaType.APPLICATION_JSON
converter.setSupportedMediaTypes(Collections.singletonList(MediaType.APPLICATION_JSON));
// 插入converts列表的第一位,防止序列中的MappingJackson2HttpMessageConverter屏蔽掉FastJsonHttpMessageConverter
converters.add(0,converter);
}
}