springboot新建的项目,其json解析默认为jackson。fastjson是阿里的一套json解析框架,功能齐全,速度更快。并且个人用的比较习惯。
因此更换json解析为fastjson。
网上百度的两种方法。具体请参考http://blog.youkuaiyun.com/xuqingge/article/details/53561529
第一种方法,继承WebMvcConfigurerAdapter,重写configureMessageConverters方法。把fastjson解析器添加。
第二种方法,代码添加fastjson解析,启动的时候添加
但是两种方法试用之后,都没有转换为fastjson转换,考虑是pom里引用的jar包有冲突。仔细查找之后,发现resteasy starter中,也引用了Jackson 作为解析方式,因此在引用
resteasy starter 的时候,去除Jackson的引用即可。测试可用
<dependency> <groupId>com.paypal.springboot</groupId> <artifactId>resteasy-spring-boot-starter</artifactId> <version>2.3.0-RELEASE</version> <exclusions> <exclusion> <groupId>org.jboss.resteasy</groupId> <artifactId>resteasy-jackson2-provider</artifactId> </exclusion> </exclusions> </dependency><!-- 引用resteasy风格 -->