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 ...
随机推荐
- JProfiler 5.1.4的使用方法
1. JProfiler运行环境配置 安装目录结构如下,子目录中显示了支持的操作系统: 在服务器和客户端都要安装JProfiler,并且要安装License,在分析工具客户端中进行安装.Windows ...
- Trigger a TTL circuit from ECL levels
ECL circuits typically have relatively small logic spans of approximately 800 mV. Because of the sma ...
- The New Virtual List Box in Delphi 6 - lbVirtual lbVirtualOwnerDraw
http://users.atw.hu/delphicikk/listaz.php?id=2471&oldal=52 Problem/Question/Abstract: What are t ...
- Spring使用@Required注解依赖检查
Spring依赖检查 bean 配置文件用于确定的特定类型(基本,集合或对象)的所有属性被设置.在大多数情况下,你只需要确保特定属性已经设置但不是所有属性.. 对于这种情况,你需要 @Required ...
- 借助Maven为项目划分development,test,production环境
原文地址:http://melin.iteye.com/blog/1339060 很早学习rails的时候,rails在服务器启动的时候,通过参数可以切换不同运行环境.也许spring从rails吸取 ...
- javascript函数中的匿名函数
一般写函数,我们会这样调用: function add(x, y) { return x + y; } alert(add(2, 3)); 或者这样: var add = function(x, y) ...
- 怎样加入cocostudio生成的UI到项目
cocos2dx版本号:cocos2d-x-3.2alpha0 cocostudio版本号:V1.4.0.1 1.将cocostudio生成的UI文件复制到项目Resources目录 2.加入头文件, ...
- combogrid翻页后保持显示内容为配置的textField解决办法
easyui的combogrid当配置pagination为true进行分页时,当datagrid加载其他数据页,和上一次选中的valueField不匹配时,会导致combogrid直接显示value ...
- 深入理解Apache Flink核心技术
深入理解Apache Flink核心技术 2016年02月18日 17:04:03 阅读数:1936 标签: Apache-Flink数据流程序员JVM 版权声明:本文为博主原创文章,未经博主允许 ...
- Django的restful api自动生成工具django-rest-swagger介绍
源码位置:https://github.com/marcgibbons/django-rest-swagger 文档位置:https://marcgibbons.com/django-rest-swa ...