1

springboot(15)修改HTTP默认序列化工具

 2 years ago
source link: https://wakzz.cn/2018/05/22/springboot/(15)%E4%BF%AE%E6%94%B9HTTP%E9%BB%98%E8%AE%A4%E5%BA%8F%E5%88%97%E5%8C%96%E5%B7%A5%E5%85%B7/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

springboot(15)修改HTTP默认序列化工具

祈雨的博客
2018-05-22

使用fastjson替代springboot默认的序列化工具

@Configuration
public class FormatConfig {

@Bean
public HttpMessageConverters fastJsonHttpMessageConverters() {
FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
FastJsonConfig fastJsonConfig = new FastJsonConfig();
fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
fastConverter.setFastJsonConfig(fastJsonConfig);
HttpMessageConverter<?> converter = fastConverter;
return new HttpMessageConverters(converter);
}
}

踩坑记录:

使用注解@EnableWebMvc之后,该注解会使用jackson作为默认序列化工具,导致以上代码失效!!!!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK