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. Consul 常用指令

    Consul 常用指令 # 通告地址 -advertise # 集群节点之间通信地址 -bind # 设置服务器为bootstrap模式.在一个dc中只有一个server处于bootstrap模式.一 ...

  2. centos6安装配置zabbix3主控端

    Centos 6.5 Zabbix 3.0.4 zabbix分为zabbix-server(主控端)和zabbix-agent(被控端),本文只介绍server: 安装mysql mysql建议使用5 ...

  3. mysql密码的查看/修改

    2.Mysql的Root密码忘记----查看或修改方法 2.1)启动命令行:windows微标键+R 2.2)在命令行输入taskkill /f /im mysqld.exe 回车,暂停Mysql服务 ...

  4. Lombok 在继承类上面的注意

    找不到符号异常 在控制台项目中配置Lombok 编译会报错 找不到符号 解决 方法: 父类字段ToString不了 @Data @NoArgsConstructor @AllArgsConstruct ...

  5. Visual Studio 实用扩展工具

    Indent Guides 为每个缩进绘制一条虚线: Highlight all occurrences of selected word 高亮相关代码: Productivity Power Too ...

  6. 【Python】【运算符】

    [取模] 所谓取模运算,就是计算两个数相除之后的余数,符号是%.如a % b就是计算a除以b的余数.用数学语言来描述,就是如果存在整数n和m,其中0 <= m < b,使得a = n * ...

  7. poj 3304 Segments 线段与直线相交

    Segments Time Limit: 1000MS   Memory Limit: 65536K       Description Given n segments in the two dim ...

  8. 浅谈Static

    A: 使用场景 static可以修饰成员变量和成员方法. 什么时候使用static修饰成员变量? 加static修饰成员的时候,这个成员会被类的所有对象所共享.一般我们把共性数据定义为静态的变量 什么 ...

  9. linux软件管理之rpm管理rpm包

    使用RPM工具管理RPM包 ====================================================================================需要 ...

  10. You Dream. We Test.

      https://www.keysight.com/us/en/home.html https://www.ixiacom.com/ IXIA 被收,才发现她