spring boot默认使用的json解析框架是jackson,替换为fastjson有两种方式

1.继承WebMvcConfigurerAdapter

@SpringBootApplication
public class App 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) {
SpringApplication.run(App.class,args);
}
}

2.使用@Bean注入方式

@Configuration
public class WebMvcConfig{ @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);
}
}

SpringBoot 使用fastjson的更多相关文章

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

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

  2. SpringBoot阿里巴巴Fastjson的一些常用配置

    SpringBoot阿里巴巴Fastjson的一些常用配置 @Bean public HttpMessageConverters fastJsonHttpMessageConverters() { F ...

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

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

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

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

  5. Springboot使用FastJson后,接口返回中文乱码的问题解决。

    哎,天下文章一大抄,到处都是一模一样的教你怎么替换掉jackson成fastjson的,可后续中文乱码网上居然没一篇文章.翻了一会源码还是写个文章共享下吧.免得后来人又浪费时间折腾. 在springb ...

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

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

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

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

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

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

  9. springboot之fastjson

    <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifac ...

  10. SpringBoot笔记--FastJson

    FastJson配置 ObjectId class ObjectIdSerializer : ObjectSerializer { override fun write(serializer: JSO ...

随机推荐

  1. multiset的应用

    multiset 和set差不多 ,但是可以存储多个一样的元素

  2. thinkphp 连接数据库 & 实例化模型操作 (下接thinkphp CURD 操作)/慕课

    7.1 连接数据库 (06:15) 1 7.2实例化模型 1 1.实例化基础模型 2 2. 实例化用户自定义模型 2 问题 2 3. 实例化公共模型 4 4. 实例化空模型 7    7.1 连接数据 ...

  3. CF70D(动态凸包)

    CF70D(动态凸包) 给出q(<=1e5)个询问,每次在加上一个点,维护凸包,或者询问某个点是否在凸包内(在边上也算). 听说可以用cdq做--但是并不会.我等蒟蒻只会用平衡树做. 首先,假设 ...

  4. Python学习过程(三)

    今天我们来学习怎么从网络上抓取我们想得到的信息,要从网页上得到我们的信息,首先是从网络上通过url获取页面 的文本,先从最简单的开始,比如获取百度首页的html. 对应代码如下: 获取网页html源码 ...

  5. 关于NSFetchedResultsController的一些用法

    如何在iPhone等设备持久保存数据,需要用到Core Data,它能帮你快速而有效率的完成数据储存,Core Data 编程经常用到 NSFetchedResultsController这个类,刚开 ...

  6. MYSQL查询字段全部为中文的字段

    在实际使用mysql的过程中,会遇到这样的问题,查询字段内容全部为中文内容的数据,对于刚用mysql的小伙伴可能就比较迷失了,不知道怎么使用,其实这个问题很简单,使用下面这个sql语句就可以了 SEL ...

  7. eclipse 自定义 文档

    在这里写....

  8. [Android]Android开发艺术探索第1章笔记

    1.1 Activity 的生命周期全面分析 1.1.1 典型情况下的生命周期分析 onPause: 正在停止,正常情况下紧接着 onStop 就会被调用,然后新的 Activity 执行 onRes ...

  9. Hadoop 2.0 安装配置

    1. install jdk 2. install hadoop. 安装包hadoop-2.2.0.tar.gz存放在一个目录.并解压. 3. 修改配置文件,一般配置文件在/etc/hadoop下面. ...

  10. 查看linux系统各种参数配置的命令

    查看linux系统各种参数配置的命令 last |grep shutdown                             //查看上次关机时间 last |grep reboot     ...