zoukankan      html  css  js  c++  java
  • Spring boot配置fastjson

    pom 文件引用

    <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>fastjson</artifactId>
                <version>1.2.34</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
  • 相关阅读:
    临时表学习
    再读《黄金时代》
    shell脚本获取给定年月前一月份及后一月份
    MEMORY_TARGET not supported on this system
    2013年的总结
    windows live writer试试
    入园第一篇
    工作中经常用到的几个字符串和数组操作方法
    小程序获取用户信息失败
    前端性能优化方法概括
  • 原文地址:https://www.cnblogs.com/rufus-hua/p/7190241.html
Copyright © 2011-2022 走看看