/* 点击爆炸效果*/

SpringBoot升级版本导致@JsonIgnore失效问题

1.@JsonIgnore换成阿里那个json@JSONField(serialize = false)

2.配置全局null字段不显示以及日期格式

@Bean
    public HttpMessageConverters fastJsonHttpMessageConverters() {
        FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
        FastJsonConfig fastJsonConfig = new FastJsonConfig();
        fastJsonConfig.setSerializerFeatures(
                /*SerializerFeature.WriteMapNullValue,*/
                SerializerFeature.WriteNullListAsEmpty,
                SerializerFeature.WriteNullStringAsEmpty,
                SerializerFeature.WriteNullBooleanAsFalse
//                SerializerFeature.WriteDateUseDateFormat
        );
        fastConverter.setFastJsonConfig(fastJsonConfig);

       //全局指定了日期格式
        fastJsonConfig.setDateFormat("yyyy-MM-dd");///* HH:mm:ss*/

        //该设置目的,为了兼容jackson
        fastConverter.setSupportedMediaTypes(Arrays.asList(MediaType.APPLICATION_JSON,MediaType.APPLICATION_JSON_UTF8,MediaType.APPLICATION_OCTET_STREAM));
        HttpMessageConverter<?> converter = fastConverter;
        return new HttpMessageConverters(converter);
    }

  

posted @ 2021-05-17 14:42  tom的猫  阅读(845)  评论(0编辑  收藏  举报