首页 > 其他分享 >使用Fastjson作为http消息转换器

使用Fastjson作为http消息转换器

时间:2022-12-01 20:32:51浏览次数:75  
标签:Fastjson convert FastJsonHttpMessageConverter http fastConverter 添加 new 转换器 fast


主要是 创建 FastJsonHttpMessageConverter 的实例。


    @Bean
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);
}

标签:Fastjson,convert,FastJsonHttpMessageConverter,http,fastConverter,添加,new,转换器,fast
From: https://blog.51cto.com/u_15815563/5904086

相关文章