异常为
com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `java.util.Date` from String "2021-07-27 10:35:16": not a valid representation (error: Failed to parse Date value '2021-07-27 10:35:16': Cannot parse date "2021-07-27 10:35:16": while it seems to fit format 'yyyy-MM-dd'T'HH:mm:ss.SSSZ', parsing fails (leniency? null))
原因
使用OpenFeign进行服务间调用时返回的对象中时间类型为字符串型,接收的对象对应的类型为Date类型,openFeign转换日期格式时异常
解决方法
1.配置文件中加
spring.jackson.timeZone=GMT+08:00
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.serialization.write_dates_as_timestamps=false
spring:
jackson:
timeZone: GMT+08:00
date-format: yyyy-MM-dd HH:mm:ss
serialization.write_dates_as_timestamps: false
2、字段上加一下注解
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createTime;