资讯详情

JSON parse error: Cannot deserialize value of type `java.util.Date` from String “2022-06-20T12:26:..

在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;

标签: 20t20nh光电传感器

锐单商城拥有海量元器件数据手册IC替代型号,打造 电子元器件IC百科大全!

锐单商城 - 一站式电子元器件采购平台