在feign在调用过程中(返回实体类)遇到了一个关于分析日期格式的错误:
Caused by: org.springframework.web.client.RestClientException: Error while extracting response for type [class com.cjw.order.entity.UserMemberDTO] 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 "2022-06-20T12:26:06.000 0000": not a valid representation (error: Failed to parse Date value '2022-06-20T12:26:06.000 0000': Unparseable date: "2022-06-20T12:26:06.000 0000"); nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `java.util.Date` from String "2022-06-20T12:26:06.000 0000": not a valid representation (error: Failed to parse Date value '2022-06-20T12:26:06.000 0000': Unparseable date: "2022-06-20T12:6:06.000+0000")
at [Source: (PushbackInputStream); line: 1, column: 545] (through reference chain: com.cjw.order.entity.UserMemberDTO["gmtCreate"])
at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:119)
at org.springframework.cloud.openfeign.support.SpringDecoder.decode(SpringDecoder.java:59)
at org.springframework.cloud.openfeign.support.ResponseEntityDecoder.decode(ResponseEntityDecoder.java:62)
at feign.optionals.OptionalDecoder.decode(OptionalDecoder.java:36)
at feign.SynchronousMethodHandler.decode(SynchronousMethodHandler.java:178)
... 60 more
解决办法,加个注解
@JsonFormat(pattern="yyyy-MM-dd")
private Date gmtCreate;