解决方法
在对应字段添加上@JsonFormat
注解即可,其中pattern的值与返回的格式相同。
如:
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private Date triggerTime;
如果在结果集中,该字段全部为null的话,由于没有进行反序列化操作,所以也无需使用这个注解,但是为了严谨还是加上为好。
详细报错
feign.codec.DecodeException: Error while extracting response for type [com.cestc.baseinterface.bean.ReturnT<com.cestc.baseinterface.bean.LogParamVo>] and content type [application/json;charset=UTF-8]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize value of type `java.util.Date` from String "2020-06-08 01:05:17": not a valid representation (error: Failed to parse Date value '2020-06-08 01:05:17': Cannot parse date "2020-06-08 01:05:17": while it seems to fit format 'yyyy-MM-dd'T'HH:mm:ss.SSSZ', parsing fails (leniency? null)); nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `java.util.Date` from String "2020-06-08 01:05:17": not a valid representation (error: Failed to parse Date value '2020-06-08 01:05:17': Cannot parse date "2020-06-08 01:05:17": while it seems to fit format 'yyyy-MM-dd'T'HH:mm:ss.SSSZ', parsing fails (leniency? null))
at [Source: (PushbackInputStream); line: 1, column: 480] (through reference chain: com.cestc.baseinterface.bean.ReturnT["content"]->com.cestc.baseinterface.bean.LogParamVo["xxlJobLogVoList"]->java.util.ArrayList[0]->com.cestc.baseinterface.bean.XxlJobLogVo["triggerTime"])
Caused by: org.springframework.web.client.RestClientException: Error while extracting response for type [com.cestc.baseinterface.bean.ReturnT<com.cestc.baseinterface.bean.LogParamVo>] and content type [application/json;charset=UTF-8]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize value of type `java.util.Date` from String "2020-06-08 01:05:17": not a valid representation (error: Failed to parse Date value '2020-06-08 01:05:17': Cannot parse date "2020-06-08 01:05:17": while it seems to fit format 'yyyy-MM-dd'T'HH:mm:ss.SSSZ', parsing fails (leniency? null)); nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `java.util.Date` from String "2020-06-08 01:05:17": not a valid representation (error: Failed to parse Date value '2020-06-08 01:05:17': Cannot parse date "2020-06-08 01:05:17": while it seems to fit format 'yyyy-MM-dd'T'HH:mm:ss.SSSZ', parsing fails (leniency? null))
at [Source: (PushbackInputStream); line: 1, column: 480] (through reference chain: com.cestc.baseinterface.bean.ReturnT["content"]->com.cestc.baseinterface.bean.LogParamVo["xxlJobLogVoList"]->java.util.ArrayList[0]->com.cestc.baseinterface.bean.XxlJobLogVo["triggerTime"])
Caused by: org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize value of type `java.util.Date` from String "2020-06-08 01:05:17": not a valid representation (error: Failed to parse Date value '2020-06-08 01:05:17': Cannot parse date "2020-06-08 01:05:17": while it seems to fit format 'yyyy-MM-dd'T'HH:mm:ss.SSSZ', parsing fails (leniency? null)); nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `java.util.Date` from String "2020-06-08 01:05:17": not a valid representation (error: Failed to parse Date value '2020-06-08 01:05:17': Cannot parse date "2020-06-08 01:05:17": while it seems to fit format 'yyyy-MM-dd'T'HH:mm:ss.SSSZ', parsing fails (leniency? null))
at [Source: (PushbackInputStream); line: 1, column: 480] (through reference chain: com.cestc.baseinterface.bean.ReturnT["content"]->com.cestc.baseinterface.bean.LogParamVo["xxlJobLogVoList"]->java.util.ArrayList[0]->com.cestc.baseinterface.bean.XxlJobLogVo["triggerTime"])