feign,get传递Date日期类型参数,序列化失败,序列化默认时间格式,非标准时间格式

报错信息

org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors Field error in object ‘orderPageWebBO’ on field ‘accompanyEstimatedStartTimeStart’: rejected value [Wed Apr 26 10:22:47 CST 2023]; codes [typeMismatch.orderPageWebBO.accompanyEstimatedStartTimeStart,typeMismatch.accompanyEstimatedStartTimeStart,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [orderPageWebBO.accompanyEstimatedStartTimeStart,accompanyEstimatedStartTimeStart]; arguments []; default message [accompanyEstimatedStartTimeStart]]; default message [Failed to convert property value of type ‘java.lang.String’ to required type ‘java.util.Date’ for property ‘accompanyEstimatedStartTimeStart’; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@io.swagger.annotations.ApiModelProperty java.util.Date] for value ‘Wed Apr 26 10:22:47 CST 2023’; nested exception is java.lang.IllegalArgumentException: Parse attempt failed for value [Wed Apr 26 10:22:47 CST 2023]]

现象

使用feign接口来进行get请求, 因为参数比较多,所有使用了对象来接收参数, 因为feign会自动将对象参数的请求转换post请求,所以使用@SpringQueryMap注解,将参数自动拼接在url上,

在传递date时间类型时,提示序列化失败问题, 原因是feign在将对象参数转换为url时,直接使用tostring默认转换方法, date默认转换这种,Wed Apr 26 10:16:06 CST 2023,默认时间格式 在反序列化时失败,

解决方法

自定义实现QueryMapEncoder类,

https://www.cnblogs.com/dai-blog/p/15921475.html 原文连接,解决方案有代码

精彩链接

评论可见,请评论后查看内容,谢谢!!!评论后请刷新页面。