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);
    }

  

上一篇:fastjson toJSON和toJSONString 时null不传的解决方式


下一篇:几种json解析工具的区别