• SpringCloud:feign默认jackson解析'yyyy-MM-ddTHH:mm:ssZ'时间格式报错


    Feign默认的使用jackson解析,所以时间传值时会报错,时间格式错误

    解决办法:

    修改feign解析方式为fastjson方式:

    @Configuration
    public class CxfConfig{
    
        @Bean
         public Encoder feignEncoder(){
            return new SpringEncoder(feignHttpMessageConverter());
        }
    
        @Bean
        public Decoder feignDecoder(){
            return new SpringDecoder(feignHttpMessageConverter());
        }
    
        /**
         *feign和Springboot使用的都是jackson,可以都修改为fastjson解析方式
         */
        private ObjectFactory<HttpMessageConverters> feignHttpMessageConverter(){
            final HttpMessageConverters httpMessageConverters = new HttpMessageConverters(this.getFastJsonConverter());
            return () -> httpMessageConverters;
        }
        
         private FastJsonHttpMessageConverter getFastJsonConverter(){
            FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
            List<MediaType> supportedMediaTypes = ArrayList<>();
            MediaType mediaTypeJson = MediaType.valueOf(MediaType.APPLICATION_JSON_UTF8_VALUE);
            supportedMediaTypes.add(mediaTypeJson);
            FastJsonConfig config = new FastJsonConfig();
            config.getSerializeConfig().put(JSON.class,new SwaggerJsonSerializer());
            config.setSerializerFeatures(SerializerFeature.DisableCircularReferenceDetect);
            converter.setFastJsonConfig(config);
            return converter;
        }
    
    }    
  • 相关阅读:
    acwing272. 最长公共上升子序列
    哈夫曼编码简单实现
    Linked List Sorting
    jmeter-线程组
    css-书写规范
    mysql-踩坑记录
    vue-npm install
    css-选择器
    js-process对象
    linux-常用命令
  • 原文地址:https://www.cnblogs.com/nhdlb/p/12783624.html
Copyright © 2020-2023  润新知