SpringCloud feign服务调用日期格式结果转换问题

假装没事ソ 提交于 2021-01-25 22:02:42

feign服务调用的具体异常信息

Error while extracting response for type [com.xxx.common.core.domain.R<com.xxx.open.api.domain.ClientAuth>] and content type [application/json]; 
nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize value of type `java.util.Date` from String \"2020-09-21 21:49:05\": not a valid representation 
(error: Failed to parse Date value '2020-09-21 21:49:05': Cannot parse date \"2020-09-21 21:49:05\": while it seems to fit format 'yyyy-MM-dd'T'HH:mm:ss.SSSX', parsing fails (leniency? null)); 
nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `java.util.Date` from String \"2020-09-21 21:49:05\": not a valid representation 
(error: Failed to parse Date value '2020-09-21 21:49:05': Cannot parse date \"2020-09-21 21:49:05\": while it seems to fit format 'yyyy-MM-dd'T'HH:mm:ss.SSSX', parsing fails (leniency? null))\n at 
[Source: (PushbackInputStream); line: 1, column: 256] (through reference chain: com.xxx.common.core.domain.R[\"data\"]->com.xxx.open.api.domain.ClientAuth[\"createTime\"])"

 这个需要在feign调用的结果里面做转换,不是在原始服务的json做格式转换

最后在date类型字段上面添加这些注解:

@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!