当前位置:
首页 >
前端技术
> javascript
>内容正文
javascript
SpringBoot 使用fastjson
生活随笔
收集整理的这篇文章主要介绍了
SpringBoot 使用fastjson
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
spring boot默认使用的json解析框架是jackson,替换为fastjson有两种方式
1.继承WebMvcConfigurerAdapter
@SpringBootApplication public class App extends WebMvcConfigurerAdapter{@Overridepublic void configureMessageConverters(List<HttpMessageConverter<?>> converters) {super.configureMessageConverters(converters);FastJsonHttpMessageConverter fastConverter=new FastJsonHttpMessageConverter(); FastJsonConfig fastJsonConfig=new FastJsonConfig();fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);fastConverter.setFastJsonConfig(fastJsonConfig);converters.add(fastConverter);}public static void main(String[] args) {SpringApplication.run(App.class,args);} }2.使用@Bean注入方式
@Configuration public class WebMvcConfig{@Beanpublic HttpMessageConverters fastJsonHttpMessageConverters(){FastJsonHttpMessageConverter fastConverter=new FastJsonHttpMessageConverter(); FastJsonConfig fastJsonConfig=new FastJsonConfig();fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat); fastConverter.setFastJsonConfig(fastJsonConfig);HttpMessageConverter<?> converter=fastConverter;return new HttpMessageConverters(converter);} }
转载于:https://www.cnblogs.com/april-chen/p/9012487.html
总结
以上是生活随笔为你收集整理的SpringBoot 使用fastjson的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: centos6创建用户,设置ssh登录
- 下一篇: Java JSON 之 Xml 转 JS