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

  • 相关阅读:
    HandlerThread
    handler原理
    死锁简析
    Android序列化
    AsyncTask原理
    【java线程池】
    java创建线程的三种方式
    service相关
    【hashMap】详谈
    【activity任务栈】浅析
  • 原文地址:https://www.cnblogs.com/javafucker/p/9719293.html
Copyright © 2011-2022 走看看