项目开始的时候就会加载这个配置,设置项目返回的JSON,因为有fastjson和jsckson等,这里设置采用fastjson
@Configuration
public class MyConfigurationTest {
@Bean
public HttpMessageConverters fastJsonHttpMessageConverters() {
// 1、定义一个 convert 转换消息的对象
FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
//2、添加fastJson 的配置信息,比如:是否要格式化返回的json数据
FastJsonConfig fastJsonConfig = new FastJsonConfig();
fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
//3、在convert中添加配置信息
fastConverter.setFastJsonConfig(fastJsonConfig);
HttpMessageConverter<?> converter = fastConverter;
return new HttpMessageConverters(converter);
}
}