Spring boot配置fastjson
pom 文件引用
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.</version>
</dependency>
bean注入(配置在 SpringBootApplication 的启动类中) ps:已解决中文乱码问题
/**
* Created by Rufus-Home on 2017/7/16.
*/
@Configuration
@ConditionalOnClass({JSON.class})
public class FastJsonHttpMessageConvertersConfiguration { @Bean
public HttpMessageConverters fastJsonHttpMessageConverters() {
FastJsonHttpMessageConverter4 fastConverter = new FastJsonHttpMessageConverter4();
FastJsonConfig fastJsonConfig = new FastJsonConfig();
fastJsonConfig.setSerializerFeatures(
SerializerFeature.PrettyFormat,
SerializerFeature.WriteMapNullValue
);
fastConverter.setFastJsonConfig(fastJsonConfig);
fastConverter.setSupportedMediaTypes(Arrays.asList(MediaType.APPLICATION_JSON_UTF8, MediaType.parseMediaType("text/html;charset=UTF-8")));
HttpMessageConverter<?> converter = fastConverter; return new HttpMessageConverters(converter);
}
}
//ps:如果使用 spring-boot 版本<=1.2.8 (因为1.2.8使用 spring-webmvc 版本为 4.1.9.RELEASE 如果升级4.2(包含4.2)以上忽略)请使用 FastJsonHttpMessageConverter替代FastJsonHttpMessageConverter4 由于spring boot 默认使用jackson 这里附上jackson配置时间的方法: (我使用的是application.yaml)
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
Spring boot配置fastjson的更多相关文章
- spring boot 配置 fastjson 替代 Jackson (并解决返回字符串带双引号问题)
注:以我遇到的情况,只要发出的请求参数是map格式的,都会在前后多加一个双引号 以下代码有两个功能:1.FastJson 替换 Spring 自带的 Jackson 2.解决返回的字符串带双引号问题 ...
- Spring Boot配置FastJson报错'Content-Type' cannot contain wildcard type '*'
升级到最新版本的fastjson以后报的错,查了一下资料,发现 fastjson从1.1.41升级到1.2.28之后,请求报错:json java.lang.IllegalArgumentExcept ...
- spring boot 之fastJson的使用(二)
昨天说了springboot的简单入门程序.今天进一步深入.今天说一下,fastJson的使用.做过springmvc的都知道fastjson.其实boot自带json可是本人用惯了fastjson, ...
- Spring Boot -- 配置切换指南
一般在一个项目中,总是会有好多个环境.比如: 开发环境 -> 测试环境 -> 预发布环境 -> 生产环境 每个环境上的配置文件总是不一样的,甚至开发环境中每个开发者的环境可能也会有一 ...
- Spring Boot 配置优先级顺序
一般在一个项目中,总是会有好多个环境.比如: 开发环境 -> 测试环境 -> 预发布环境 -> 生产环境 每个环境上的配置文件总是不一样的,甚至开发环境中每个开发者的环境可能也会有一 ...
- spring boot 配置注入
spring boot配置注入有变量方式和类方式(参见:<spring boot 自定义配置属性的各种方式>),变量中又要注意静态变量的注入(参见:spring boot 给静态变量注入值 ...
- Spring boot配置多个Redis数据源操作实例
原文:https://www.jianshu.com/p/c79b65b253fa Spring boot配置多个Redis数据源操作实例 在SpringBoot是项目中整合了两个Redis的操作实例 ...
- spring boot配置springMVC拦截器
spring boot通过配置springMVC拦截器 配置拦截器比较简单, spring boot配置拦截器, 重写preHandle方法. 1.配置拦截器: 2重写方法 这样就实现了拦截器. 其中 ...
- spring boot配置mybatis和事务管理
spring boot配置mybatis和事务管理 一.spring boot与mybatis的配置 1.首先,spring boot 配置mybatis需要的全部依赖如下: <!-- Spri ...
随机推荐
- Redis-环境搭建、创建服务、搭建主从复制-Windows版本
一.搭建Redis环境 1.链接:http://pan.baidu.com/s/1boKAzzL 密码:sh2r 2.不赘述:执行redis-server.再执行redis-cli即可.redis环境 ...
- 【转】2012年6月26 – 盛大PHP工程师最新面试题
无笔试. 口试:(前半部分平淡无奇,没什么太难的问题,都是求职岗位基本要会的东西,局限于php.下面是真正进入状态的题.) 谈谈观察者模式是什么?主要应用. 答:类似会有一些server对象时刻侦听某 ...
- MySql清空表的方法介绍 : truncate table 表名
清空某个mysql表中所有内容 delete from 表名; truncate table 表名; 不带where参数的delete语句可以删除mysql表中所有内容,使用truncate tabl ...
- VS2017安装后如何移动 Windows Kits文件夹
MS的回答 LINK Try the following technique: Close all programs, move the “Windows Kits” folder to anothe ...
- JACOB的语法
转自:http://www.bitscn.com/pdb/java/200904/161117.html 如果你想写一个JAVA代码,其中需要调用JACOB提供的功能,而你还是新手,也许篇文章会大大降 ...
- maven编译错误,警告: BASE64Decoder是内部专用 API, 可能会在未来发行版中删除
修改红色部分版本号为2.3.2 <plugin> <groupId>org.apache.maven.plugins& ...
- 深入理解Apache Flink核心技术
深入理解Apache Flink核心技术 2016年02月18日 17:04:03 阅读数:1936 标签: Apache-Flink数据流程序员JVM 版权声明:本文为博主原创文章,未经博主允许 ...
- GIF 屏幕录制工具
LICEcap是一款屏幕录制工具,支持导出 GIF 动绘图片格式,轻量级.使用简单,录制过程中能够任意改变录屏范围. .捕捉屏幕的区域并保存为.GIF动画(便于网络公布)或.L ...
- Linux下Oracle 10g DataGuard配置(主从同步及切换)
环境描述:主库: IP: 10.8.3.191 主机名:primaryORACLE_SID=afcORACLE_BASE=/u01/oracleORACLE_HOME=/u01/oracle/10g备 ...
- Orchard运用 - 网站样例
在此分享一些个人觉得比较不错的基于Orhcard搭建的网站. 中文版: http://www.58img.com/ http://www.weijiqiong.com/ http://www.apma ...