1.先在项目中添加fastjson依赖:

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>

2.1第一种方法,让入口类实现WebMvcConfigure接口,并重写configureMessageConverters方法:

public class App implements WebMvcConfigurer{
......
}
重写方法:
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
//第一种配置fastJson方法
FastJsonHttpMessageConverter fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter();
FastJsonConfig fastJsonConfig = new FastJsonConfig();
fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
//处理中文乱码问题
List<MediaType> fastMediaTypes = new ArrayList<MediaType>();
fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
fastJsonHttpMessageConverter.setSupportedMediaTypes(fastMediaTypes); fastJsonHttpMessageConverter.setFastJsonConfig(fastJsonConfig);
converters.add(fastJsonHttpMessageConverter); }

2.2第二种方法,直接在入口类加入@Bean注解并加入方法:

@Bean
public HttpMessageConverters fastJsonHttpMessage() {
FastJsonHttpMessageConverter fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter();
FastJsonConfig fastJsonConfig = new FastJsonConfig();
fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
//处理中文乱码问题
List<MediaType> fastMediaTypes = new ArrayList<MediaType>();
fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
fastJsonHttpMessageConverter.setSupportedMediaTypes(fastMediaTypes); fastJsonHttpMessageConverter.setFastJsonConfig(fastJsonConfig);
return new HttpMessageConverters(fastJsonHttpMessageConverter);
}

  

SpringBoot 添加fastjson的更多相关文章

  1. springboot使用fastjson中文乱码解决方法 【转载】

    以前使用fastjson替换jackson时,没有直接在页面打印过json,都是js使用没有出现乱码,偶然 打印出来出现了中文乱码 之前使用的配置方式 @Configuration public cl ...

  2. springboot整合fastJson遇到重定向问题

    通过网上教程使用springboot整合fastJson后遇到页面重定向问题(使用的springboot版本是2.0.2.RELEASE ,其他的版本可能不会出现以下问题),如下图: 我的项目结构如下 ...

  3. SpringBoot中用Fastjson替换默认的Jackson

    一:前言 经过测试,Jackson有很多不合人意的地方,因此建议用Fastjson来替换: 二:Jackson的坑 先定义实体类: @Data @AllArgsConstructor @NoArgsC ...

  4. SpringBoot添加自定义消息转换器

    首先我们需要明白一个概念:springboot中很多配置都是使用了条件注解进行判断一个配置或者引入的类是否在容器中存在,如果存在会如何,如果不存在会如何. 也就是说,有些配置会在springboot中 ...

  5. 十七、springboot配置FastJson为Spring Boot默认JSON解析框架

    前提 springboot默认自带json解析框架,默认使用jackson,如果使用fastjson,可以按照下列方式配置使用 1.引入fastjson依赖库: maven: <dependen ...

  6. springboot使用fastJson作为json解析框架

    springboot使用fastJson作为json解析框架 springboot默认自带json解析框架,默认使用jackson,如果使用fastjson,可以按照下列方式配置使用 〇.搭建spri ...

  7. 【Springboot】FastJson与Jackson全局序列化方式的配置和相关工具类

    springboot 版本: <parent> <groupId>org.springframework.boot</groupId> <artifactId ...

  8. Springboot添加filter方法

    在springboot添加filter有两种方式: (1).通过创建FilterRegistrationBean的方式(建议使用此种方式,统一管理,且通过注解的方式若不是本地调试,如果在filter中 ...

  9. springboot添加邮件发送及压缩功能

    springboot添加邮件发送及文件压缩功能 转载请注明出处:https://www.cnblogs.com/funnyzpc/p/9190233.html 先来一段诗 ``` 就这样吧 忍受折磨 ...

随机推荐

  1. stl中常用的排序算法

    #include"iostream" #include"vector" using namespace std; #include"string&qu ...

  2. java解析前端请求接口的全部入参

    第一种: public static String getRequestInput(HttpServletRequest request) { StringBuilder sb = new Strin ...

  3. HDU-6336-构造

    Problem E. Matrix from Arrays Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 ...

  4. Tips about Troubleshooting RAC

    Installation Log Filessoftware installation log files inside the logs directory of Oracle central in ...

  5. Windows与Linux的回车换行转换

    最初"\r"(return)表示“回车”即回到行首,“\n”(next)表示“换行”即定位到下一行:UNIX和Linux使用“\n”换行,而Windows用“\r\n”(不是\n\ ...

  6. python xlrd使用

    python xlrd使用 1● xlrd安装   管理员模式           success 2● 引用 import xlrd    

  7. codeigniter在nginx下返回404 not found

    codeigniter框架需要path_info的支持,Apache默认支持path_info,但是nginx默认不支持,我们需要设置nginx,使得nginx支持path_info 网上试了好多方法 ...

  8. 双向链表--首页大小不一卡片排序 --- react --- js

    1.4中类型(grid_type)的卡片:1:大方块:2:竖长块:3:横长块:4:小方块 var order = 0; // 创建链表 function List(head) { this.head ...

  9. Python Django 之 直接执行自定义SQL语句(一)

    一.执行自定义SQL方法 1.Executing custom SQL directly      直接执行自定义SQL,这种方式可以完全避免数据模型,而是直接执行原始的SQL语句. 2.Manage ...

  10. asp.net中HttpModule扩展的浅析

    在asp.net中,我们可以使用HttpModule扩展自己的相关业务.可以在HttpApplication的19个管道事件中注入我们自己的业务逻辑代码. 闲话不说,代码先上. 一.新建网站项目 我们 ...