Spring Boot perfectly uses FastJson to parse JSON data
import dependency jar
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.15</version>
</dependency>
1st implementation
The first method is:
( 1 ) The startup class inherits extends WebMvcConfigurerAdapter
( 2 ) Override the method configureMessageConverters
@SpringBootApplication public class StartApp extends WebMvcConfigurerAdapter { @Override public 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) { String[] agrs11 = {"Jimmy","Gougo1u","Do1ggy"}; ApplicationContext applicationContext = SpringApplication.run(Start.class, agrs11); } }
The second implementation
( 1 ) In the App.java startup class ,
Inject Bean : HttpMessageConverters
@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); }