写BUG的派大星

Patrick Star

  • 首页
  • 归档

  • 搜索
设计模式 Gis Kafka Druid 微信小程序 Java 开源项目源码 物体识别 机器学习 Mybatis 微服务 Feign OpenVPN CSS Streamsets CDH SpringCloud SpringBoot maven 分布式 Shell Tree Linux js WebSocket 多线程 集群 Hadoop 大数据 JDK ElasticSearch MySQL 数据库 Redis Http Nginx

SpringBoot反序列化日期类型报错

发表于 2020-06-08 | 分类于 Java | 0 | 阅读次数 1941

解决方法

在对应字段添加上@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"])
  • 本文作者: Patrick
  • 本文链接: https://www.write1bug.cn/archives/springboot反序列化日期类型报错
  • 版权声明: 本博客所有文章除特别声明外,均采用CC BY-NC-SA 3.0 许可协议。转载请注明出处!
# 设计模式 # Gis # Kafka # Druid # 微信小程序 # Java # 开源项目源码 # 物体识别 # 机器学习 # Mybatis # 微服务 # Feign # OpenVPN # CSS # Streamsets # CDH # SpringCloud # SpringBoot # maven # 分布式 # Shell # Tree # Linux # js # WebSocket # 多线程 # 集群 # Hadoop # 大数据 # JDK # ElasticSearch # MySQL # 数据库 # Redis # Http # Nginx
在Web页面中打开QQ聊天
网页滚动条美化
  • 文章目录
  • 站点概览
Patrick

Patrick

不是在改BUG,就是在写BUG。

52 日志
9 分类
36 标签
RSS
E-mail
Creative Commons
© 2018 — 2023 Patrick
人生如逆旅|我亦是行人
鲁ICP备18043140号-1