zoukankan      html  css  js  c++  java
  • SpringBoot阿里巴巴Fastjson的一些常用配置

    SpringBoot阿里巴巴Fastjson的一些常用配置

        @Bean
        public HttpMessageConverters fastJsonHttpMessageConverters() {
            FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
            FastJsonConfig fastJsonConfig = new FastJsonConfig();
            fastJsonConfig.setSerializerFeatures(
                    SerializerFeature.PrettyFormat,   //是否格式化输出,默认为false
                    SerializerFeature.DisableCircularReferenceDetect,   //禁止循环引用,即出现$.data[0]
                    SerializerFeature.WriteMapNullValue,   //Map字段如果为null,输出为[],而非null
                    SerializerFeature.WriteNullListAsEmpty,   //List字段如果为null,输出为[],而非null
                    SerializerFeature.WriteNullStringAsEmpty   //字符类型字段如果为null,输出为”“,而非null
            );
            fastJsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss");   //统一配置日期格式
            fastJsonConfig.setCharset(Charset.forName("UTF-8"));
            fastConverter.setFastJsonConfig(fastJsonConfig);
            HttpMessageConverter<?> converter = fastConverter;
            return new HttpMessageConverters(converter);
        }

    当配置了“SerializerFeature.WriteMapNullValue”这一类配置之后,当返回值中的该字段为null,将输出字段,如果不配置,那该字段将不会显示

    引用文章:https://blog.csdn.net/u010246789/article/details/52539576

  • 相关阅读:
    逆变和协变
    委托的泛型版本
    委托的协变和逆变
    IIS8应用池重启脚本
    JS获取url参数及url编码、解码
    Jmeter压测Thrift服务接口
    浏览器插件及好用的小工具
    Jmeter入门实例
    BugBash活动分享
    如何作缺陷分析
  • 原文地址:https://www.cnblogs.com/javafucker/p/9719293.html
Copyright © 2011-2022 走看看