• 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;
        }
    
    }    
  • 相关阅读:
    蓝桥杯省赛经验
    阅读笔记四
    阅读笔记二
    阅读笔记一
    动态规划——Maximum Sum of 3 Non-Overlapping Subarrays
    动态规划——Remove Boxes
    动态规划——Dungeon Game
    动态规划——Freedom Trail
    动态规划——Frog Jump
    《软件需求十步走》阅读笔记一
  • 原文地址:https://www.cnblogs.com/nhdlb/p/12783624.html
Copyright © 2020-2023  润新知