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的更多相关文章

  1. spring boot 配置 fastjson 替代 Jackson (并解决返回字符串带双引号问题)

    注:以我遇到的情况,只要发出的请求参数是map格式的,都会在前后多加一个双引号 以下代码有两个功能:1.FastJson 替换 Spring 自带的 Jackson  2.解决返回的字符串带双引号问题 ...

  2. Spring Boot配置FastJson报错'Content-Type' cannot contain wildcard type '*'

    升级到最新版本的fastjson以后报的错,查了一下资料,发现 fastjson从1.1.41升级到1.2.28之后,请求报错:json java.lang.IllegalArgumentExcept ...

  3. spring boot 之fastJson的使用(二)

    昨天说了springboot的简单入门程序.今天进一步深入.今天说一下,fastJson的使用.做过springmvc的都知道fastjson.其实boot自带json可是本人用惯了fastjson, ...

  4. Spring Boot -- 配置切换指南

    一般在一个项目中,总是会有好多个环境.比如: 开发环境 -> 测试环境 -> 预发布环境 -> 生产环境 每个环境上的配置文件总是不一样的,甚至开发环境中每个开发者的环境可能也会有一 ...

  5. Spring Boot 配置优先级顺序

    一般在一个项目中,总是会有好多个环境.比如: 开发环境 -> 测试环境 -> 预发布环境 -> 生产环境 每个环境上的配置文件总是不一样的,甚至开发环境中每个开发者的环境可能也会有一 ...

  6. spring boot 配置注入

    spring boot配置注入有变量方式和类方式(参见:<spring boot 自定义配置属性的各种方式>),变量中又要注意静态变量的注入(参见:spring boot 给静态变量注入值 ...

  7. Spring boot配置多个Redis数据源操作实例

    原文:https://www.jianshu.com/p/c79b65b253fa Spring boot配置多个Redis数据源操作实例 在SpringBoot是项目中整合了两个Redis的操作实例 ...

  8. spring boot配置springMVC拦截器

    spring boot通过配置springMVC拦截器 配置拦截器比较简单, spring boot配置拦截器, 重写preHandle方法. 1.配置拦截器: 2重写方法 这样就实现了拦截器. 其中 ...

  9. spring boot配置mybatis和事务管理

    spring boot配置mybatis和事务管理 一.spring boot与mybatis的配置 1.首先,spring boot 配置mybatis需要的全部依赖如下: <!-- Spri ...

随机推荐

  1. Python类中self的作用

    摘自论坛: self:是指向你新创建对象实例的引用,在这个地方指向你创建的Person类的实例p.当你调用Person类创建实例时,self指的就是你这个P,所以这个地方p=Person('tiany ...

  2. 利用BusyBox ~私人定制 My LINUX~

    前言 我在今天在这里跟大家详细地探讨一下Linux系统的定制过程和实现例如.用户能够远程登录:和Nginx能够稳定地运行在我们私人定制的LINUX系统上.一步一步从头开始定制属于我们自己的系统. 正文 ...

  3. 蓝屏代码详解(更新WIN7蓝屏代码)

    6位代码含意 0 0x0000 作业完成.  1 0x0001 不正确的函数.  2 0x0002 系统找不到指定的档案.  3 0x0003 系统找不到指定的路径.  4 0x0004 系统无法开启 ...

  4. Simple microcontroller-temperature measurement uses only a diode and a capacitor

    Using a PN-junction diode for temperature measurement usually depends on its 2‑mV/K temperature  coe ...

  5. loading(正在加载特效)

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  6. rc_80 tomcat 日志

    1 #!/bin/sh 2 cd /mnt/tomcat/tomcat_8082/logs; 3 tail -f catalina.out;

  7. Python continue 语句

    Python continue 语句 Python continue 语句跳出本次循环,而break跳出整个循环. continue 语句用来告诉Python跳过当前循环的剩余语句,然后继续进行下一轮 ...

  8. springboot2.X整合mybatis

    github地址:https://github.com/BenchChen/springboot 1) 创建springboot-maven项目,并修改pom文件 <?xml version=& ...

  9. EntityFramework:我想我需要和 Session.Save 语义一样的方法

    背景 EntityFramework 中 DbSet.Add 方法不会导致立即执行 insert 语句,这在长事务中非常有用,不过多数用例都是短事务的,为何我需要一个立即执行 insert 语句的方法 ...

  10. [android] Activity 的生命周期 以及横屏竖屏切换时 Activity 的状态变化

    生命周期Android 系统在Activity 生命周期中加入一些钩子,我们可以在这些系统预留的钩子中做一些事情.例举了 7 个常用的钩子:protected void onCreate(Bundle ...