1.问题排查

项目配置

  • springboot 2.1
  • Mave配置Jackson依赖

出现的场景

  • 服务端通过springmvc写了一个对外的接口,查询数据中的表,表中有一个字段属性是时间戳,返回一个json字符串,其中该json带有日期,格式为yyyy-MM-dd HH:mm:ss
  • 客户端调用该http接口,指定返回值为一个Vo,Vo中日期的字段为Date类型
  • 客户端调用该接口后抛异常了。报错信息如下:
feign.codec.DecodeException: JSON parse error: Can not deserialize value of type java.util.Date from String "2018-03-07 16:18:35": not a valid representation (error: Failed to parse Date value '2018-03-07 16:18:35': Can not parse date "2018-03-07 16:18:35Z": while it seems to fit format 'yyyy-MM-dd'T'HH:mm:ss.SSS'Z'', parsing fails (leniency? null)); nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Can not deserialize value of type java.util.Date from String "2018-03-07 16:18:35": not a valid representation (error: Failed to parse Date value '2018-03-07 16:18:35': Can not parse date "2018-03-07 16:18:35Z": while it seems to fit format 'yyyy-MM-dd'T'HH:mm:ss.SSS'Z'', parsing fails (leniency? null))

2.解决方法

因为数据库中存在一个create_time字段,属性是timestamp,服务器端查询数据库并把字段映射到定义的Vo中出现了格式问题,所以在Vo中把createTime添加@JsonFormat注释就可以完成时间字段映射的格式问题。

@JsonFormat( pattern="yyyy-MM-dd HH:mm:ss")
private Date createTime;

3.异常的原因

这篇博客可以了解底层报错的原因。

https://blog.csdn.net/qq906627950/article/details/79503801

【开发遇到的问题】Spring Mvc使用Jackson进行json转对象时,遇到的字符串转日期的异常处理(JSON parse error: Can not deserialize value of type java.util.Date from String[)的更多相关文章

  1. JSON parse error: Cannot deserialize value of type `java.util.Date` from String

    DateTimePicker + @DateTimeFormat("yyyy-MM-dd HH:mm:ss")日期格式转换异常 最近在做的一个项目使用的日期格式是yyyy-MM-d ...

  2. JSON parse error: Cannot deserialize value of type `java.time.LocalDateTime` from String

    在使用Postman测试Spring Boot项目接口时,接口返回JSON parse error: Cannot deserialize value of type `java.time.Local ...

  3. spring mvc出现 Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'endtime'

    在使用spring mvc中,绑定页面传递时间字符串数据给Date类型是出错: Failed to convert property value of type [java.lang.String] ...

  4. 【spring mvc】后台API查询接口,get请求,后台Date字段接收前台String类型的时间,报错default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'createDate';

    后台API查询接口,get请求,后台Date字段接收前台String类型的时间筛选条件 后台接口接收 使用的实体 而createDate字段在后台实体中是Date类型 报错信息: org.spring ...

  5. 【spring boot】spring boot 前台GET请求,传递时间类型的字符串,后台无法解析,报错:Failed to convert from type [java.lang.String] to type [java.util.Date]

    spring boot 前台GET请求,传递时间类型的字符串,后台无法解析,报错:Failed to convert from type [java.lang.String] to type [jav ...

  6. org.codehaus.jackson.map.JsonMappingException: Can not construct instance of java.util.Date from String value '20Spring Jackson 反序列化Date时遇到的问题

    Jackson对于date的反序列化只支持几种,如果不符合默认格式则会报一下错误 org.codehaus.jackson.map.JsonMappingException: Can not cons ...

  7. org.codehaus.jackson.map.JsonMappingException: Can not construct instance of java.util.Date from String value '2012-12-12 12:01:01': not a valid representation (error: Can not parse date "2012-12-

    Jackson对于date的反序列化只支持几种,如果不符合默认格式则会报一下错误 org.codehaus.jackson.map.JsonMappingException: Can not cons ...

  8. SpringMVC 集成 jackson,日志格式报错:org.codehaus.jackson.map.JsonMappingException: Can not construct instance of java.util.Date from String value

    org.codehaus.jackson.map.JsonMappingException: Can not construct instance of java.util.Date from Str ...

  9. Cannot convert value of type [java.lang.String] to required type [java.util.Date] for property 'xxx': no matching editors or conversion strategy found

    今天在完成项目的时候遇到了下面的异常信息: 04-Aug-2014 15:49:27.894 SEVERE [http-apr-8080-exec-5] org.apache.catalina.cor ...

随机推荐

  1. Docker Swarm 配置文件存储

    Docker Swarm 配置文件存储 config:宿主级容器服务配置文件单独保存到docker中存储调用. 环境: 系统:Centos 7.4 x64 应用版本:Docker 18.09.0 管理 ...

  2. onsubmit 事件

    onsubmit 事件 Event 对象 定义和用法 onsubmit 事件会在表单中的确认按钮被点击时发生. 语法 onsubmit="SomeJavaScriptCode" 参 ...

  3. #const#const int *p 为何可以不初始化

    摘自http://www.myexception.cn/cpp/1900041.html const int *p 为什么可以不初始化?c++ primer 5th   P53 写道:const 对象 ...

  4. Python2.x与3.x对比

    1.默认支持中文 2.不再兼容2.x 3.核心语法调整 4.新特性默认只支持3.x

  5. TypeError: Cannot read property 'length' of null

    本文为博主原创,未经允许不得转载: 异常展示: [Vue warn]: Error in getter for watcher "filterAndSortData": " ...

  6. python学习-----协程

    一.协程的引入 对于单线程下,我们不可避免程序中出现io操作,但如果我们能在自己的程序中(即用户程序级别,而非操作系统级别)控制单线程下的多个任务能在一个任务遇到io阻塞时就切换到另外一个任务去计算, ...

  7. Nginx教程---03.Nginx日志切割

    Nginx的定时任务与自动切割 明确: 如果这个网站的访问量比较大,那么一天下来 nginx日志可能会特别的大,所以当出现这种情况呢,如果 把每天的日志都存在同一个日志文件里,会使你的日志文件大到让你 ...

  8. .Net中json序列化与反序列化

    NuGet中下载Newtonsoft.Json插件. public class JsonHelper<T>{ public static string ModelToJsonString( ...

  9. jps: command not found

    在/etc/profile中添加javahome的 path export JAVA_HOME=/usr/java/jdk1.8.0_131export PATH=$PATH:$JAVA_HOME/b ...

  10. 7.9 GRASP原则九: 隔离变化

    GRASP原则九: 隔离变化  Protected Variations  需求一定会变化的!如何做到以系统的局部变化为代价就可以应对这一点?4.1 GRASP rule9: Protected ...