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-用思维导图二天搞定Redis用法。
Redis整体面貌 Redis基本数据结构 1.String 1.1 数据结构 long len byte数组长度 long free 可用数组长度 char buff[] 数据内容 1.2 命令 键 ...
- Druid 配置_StatFilter
Druid内置提供一个StatFilter,用于统计监控信息. 1. 别名配置 StatFilter的别名是stat,这个别名映射配置信息保存在druid-xxx.jar!/META-INF/drui ...
- 在Mac中设置Ctrl+C/V进行复制/粘贴
从Windows世界走入Mac世界,最让不习惯的是在Mac中“复制/粘贴”的快捷键是Command+C/V.而且Command键与C/V键靠得太近,只能用大拇指与食指进行操作,也让人不习惯.再加上远程 ...
- PIR人体检查
1.无变化时电压为0.8V左右 2.当检查到人体活动,电压保持为-1.3V,直到运动停止. 下面是示波器的截图
- sonar使用故障Unable to load component class org.sonar.scanner.report.ActiveRulesPublisher/Unable to load component interface org.sonar.api.batch.rule.ActiveRules: NullPointerException
nginx后两个sonar负载分担 解决办法 Credit to @teryk-sonarsource-team, just making it an answer: Delete the direc ...
- 取出html中指定id的元素的内容
private void btnGet_Click(object sender, EventArgs e) { string PageUrl = "http://www.cnblogs.co ...
- 彻底解决Odoo8.0单时区应用中的时区问题
原文地址:http://shine-it.net/index.php/topic,17001.0.html 由于数据库中存储的是UTC时区,默认情况下数据导出和group by都存在时区问题.彻底解决 ...
- 运算符重载,浅拷贝(logical copy) ,vs, 深拷贝(physical copy),三大件(bigthree problem)
一般的我们喜欢这样对对象赋值: Person p1;Person p2=p1; classT object(another_object), or A a(b); classT object = ...
- 关于Javascript你可能不知道的事
NaN表示一个不能产生正常结果的运算结果.它不等于任何值,包括它自己.可以用isNaN(number)来检测. 同Java中的字符串一样,JS中的字符串是不可变的.也就是说一旦字符串被创建,就无法改变 ...
- SVN — subclipse操作指引
摘自: http://jiangzhengjun.iteye.com/blog/491824 安装插件:请参照http://subclipse.tigris.org/servlets/ProjectP ...