主要是 创建 FastJsonHttpMessageConverter 的实例。
@Bean标签:Fastjson,convert,FastJsonHttpMessageConverter,http,fastConverter,添加,new,转换器,fast From: https://blog.51cto.com/u_15815563/5904086
public HttpMessageConverters fastJsonHttpMessageConverters() {
// 1、定义一个convert转换消息的对象
FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
// 2、添加fastjson的配置信息
FastJsonConfig fastJsonConfig = new FastJsonConfig();
fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
fastConverter.setSupportedMediaTypes(Arrays.asList(MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON_UTF8));
// 3、在convert中添加配置信息
fastConverter.setFastJsonConfig(fastJsonConfig);
// 4、将convert添加到converters中
HttpMessageConverter<?> converter = fastConverter;
return new HttpMessageConverters(converter);
}