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

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
原文连接,解决方案有代码

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值