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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sz85850597/article/details/80412137

使用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作为默认序列化工具,导致以上代码失效!!!!

猜你喜欢

转载自blog.csdn.net/sz85850597/article/details/80412137