SpringBoot 集成 阿里的 FastJson

孤街醉人 提交于 2020-11-06 07:56:40

SpringBoot 集成 fastjson

pom.xml 中添加引用

<dependency>
	<groupId>com.alibaba</groupId>
	<artifactId>fastjson</artifactId>
	<version>1.2.47</version>
</dependency>

在主类中

@Bean
public HttpMessageConverters fastJsonHttpMessageConverters() {
	FastJsonHttpMessageConverter fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter();
	FastJsonConfig fastJsonConfig = new FastJsonConfig();
	fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
	fastJsonHttpMessageConverter.setFastJsonConfig(fastJsonConfig);
	HttpMessageConverter<?> converter = fastJsonHttpMessageConverter;
	return new HttpMessageConverters(converter);
}

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!