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. visio画等分树状图

    一 树状图形状 Search里搜索Tree,找到Double Tree或者Multi Tree的形状 二 分出更多branch 按住主干上的黄色小方块,拖出更多分支. 三 等分分支 将每个分支和对应的 ...

  2. 十九、Spring框架(注解方式测试)

    一.注解方式测试 1.注解方式测试使用junit.使用junit-4.12.jar和hamcrest-all-1.3.jar(单元测试包) 把这两个jar包,导入到lib文件夹下. 2.TestSpr ...

  3. Oracle11g版本中未归档隐藏参数

    In this post, I will give a list of all undocumented parameters in Oracle 11g. Here is a query to se ...

  4. 微信小程序 获取位置、移动选点、逆地址解析

    WGS- 地心坐标系,即GPS原始坐标体系.在中国,任何一个地图产品都不允许使用GPS坐标,据说是为了保密.GoogleEarth及GPS芯片使用. .GCJ-02火星坐标系,国测局02年发布的坐标体 ...

  5. ActiveMQ 到底是推还是拉?

    http://activemq.apache.org/destination-options.html 1. consumer 的配置参数如下图: 配置consumer的示例: public void ...

  6. python列表反转函数

    def reverse(ListInput): RevList=[] for i in range (len(ListInput)): RevList.append(ListInput.pop()) ...

  7. 码云git使用一(上传本地项目到码云git服务器上)

    主要讲下如果将项目部署到码云git服务器上,然后使用studio导入git项目,修改本地代码后,并同步到码云git上面. 首先:我们在码云上注册账号并登陆.官网(https://git.oschina ...

  8. 【SQL】group by 及 having

    Group By 分组汇总 HAVING:给分组设置条件 1.概述 “Group By”从字面意义上理解就是根据“By”指定的规则对数据进行分组,所谓的分组就是将一个“数据集”划分成若干个“小区域”, ...

  9. Uboot启动流程分析(转载)

    最近一段时间一直在做uboot移植相关的工作,需要将uboot-2016-7移植到单位设计的ARMv7的处理器上.正好元旦放假三天闲来无事,有段完整的时间来整理下最近的工作成果.之前在学习uboot时 ...

  10. 用linq和datatable巧妙应用于微软报表rdlc

    看看代码吧.现在我用Linq已经上瘾,对SQL语言已经几乎不用了,可惜的是rdlc不支持linq,要采用sql语言生成datatable,用datatable绑定rdlc,这里,应用了一个技巧,解决了 ...