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. A4纸和一寸照在屏幕的尺寸计算

    参考地址 https://www.cnblogs.com/lenther2002/p/5105126.html A4纸 A4纸的尺寸是210mm×297mm. 分辨率是72像素/英寸时,A4纸的尺寸的 ...

  2. 大白话解说TCP/IP协议三次握手和四次挥手

    背景 和女朋友异地恋一年多,为了保持感情我提议每天晚上视频聊天一次. 从好上开始,到现在,一年多也算坚持下来了. 问题 有时候聊天的过程中,我的网络或者她的网络可能会不好,视频就会卡住,听不到对方的声 ...

  3. 【Java】Strategy Pattern

    前言 如果说,商场打折针对不同的时节,比如双十一.圣诞节.春节这些值得促销的好日子,进行不同程度的降价打折从而获得最大程度上的收益,如果有一群鸭子,只会游泳.嘎嘎叫,但是某一天某种类型的鸭子学会了飞, ...

  4. vee-validate使用教程

    vee-validate使用教程 *本文适合有一定Vue2.0基础的同学参考,根据项目的实际情况来使用,关于Vue的使用不做多余解释.本人也是一边学习一边使用,如果错误之处敬请批评指出* 一.安装 n ...

  5. 3. mybatis # 与 $ 的区别

    mybatis # 与 $ 的区别 1.# % 号必须写在test中 应用场景:模糊查询 配置文档mapper.xml <select id="selectBlogByTitle&qu ...

  6. gradle 使用本地maven 仓库 和 提交代码到maven

    /* * This build file was generated by the Gradle 'init' task. * * This generated file contains a sam ...

  7. P2596 [ZJOI2006]书架(splay)

    [题目链接] https://www.luogu.org/problemnew/show/P2596 平衡树,需支持五个操作: 1. 将某元素置顶:将元素旋到根,然后将左子树合并到该元素的后继 2. ...

  8. navicat data modeler的使用以及数据库设计的流程

    E-R图(Entity Relationship Diagram) 又称实体-联系图 (提供了表示实体类型.属性和联系的方法,用来描述现实世界的概念模型) 构成E-R图的3个基本要素是实体型.属性和联 ...

  9. Binutils工具集常用工具

    GNU为GCC编译器提供了配套的辅助工具集(Binutils)http://www.gnu.org/software/binutils/ 1. addr2line ①将指定地址转换为对应的文件名和行号 ...

  10. mybatis mapper问题列表

    id出现两次 2018-11-14 16:15:03.833 DEBUG 41432 --- [           main] c.a.i.o.d.mapper.DatvMapper.insert  ...