spring boot 配置fastjson
阿新 • • 發佈:2018-03-03
定義 spa lib serial spring converter res pub nconf
spring boot 默認使用的json轉換工具是jackson。
集成fastjson,pom.xml引入fastjson的jar
<dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.15</version> </dependency>
配置fastjson
啟動類註入Bean HttpMessageConverters
@Bean public HttpMessageConverters fastjsonHttpMessageConverter(){ //定義一個轉換消息的對象 FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter(); //添加fastjson的配置信息 比如 :是否要格式化返回的json數據 FastJsonConfig fastJsonConfig = new FastJsonConfig(); fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);//在轉換器中添加配置信息 fastConverter.setFastJsonConfig(fastJsonConfig); HttpMessageConverter<?> converter = fastConverter; return new HttpMessageConverters(converter); }
spring boot 配置fastjson