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. 【题解】JSOIWC2019 Round4

    题面: https://files-cdn.cnblogs.com/files/yzhang-rp-inf/P13.gif https://files-cdn.cnblogs.com/files/yz ...

  2. 【题解】Luogu P2057 [SHOI2007]善意的投票

    原题传送门 我们一眼就能看出这是一道最小割的题 我们设不睡觉这种状态为S,睡觉这种状态为T 对于每个人,如果不想睡觉,就从S向这个人连流量为1的边,否则,就从这个人向T连流量为1的边 对于每一对朋友, ...

  3. python学习笔记:装饰器2

    python的装饰器本质是函数,为了不改变装饰目标函数内部代码而增加额外功能而存在 一.一般装饰函数实例: import datetime def func_name(func):#定义一个装饰函数, ...

  4. MySql 中的<=>操作符

    今天在学习数据库的索引优化时,关于memory存储引擎的的hash索引时,看到了操作符<=> ,这个操作符还是第一次见到,于是上网查了一下.我想大家应该知道 =  !=   <> ...

  5. Bugku-CTF之网站被黑(这个题没技术含量但是实战中经常遇到)

    Day11   网站被黑   http://123.206.87.240:8002/webshell/    

  6. [LspTrace]ReadAccConfig returns false! QT

    当qt运行出现以下信息时 [LspTrace]ReadAccConfig returns false! [LspTrace]FindMatchingProvider: inInfo is one of ...

  7. maven开发项目中遇到的问题

    java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start com ...

  8. ssh远程登陆和MTR测试

    ssh -p 22 root@142.234.255.66 which mtr yum install mtr -y mtr -c 20 -n --report www.baidu.com mtr - ...

  9. [Hibernate] 分页查询

    @Test public void test9(){ //根据部门编号进行分组,再根据每个部门总工资>5000 Session ss=HibernateUtil.getSession(); St ...

  10. 使用Python访问微信

    itchat是一个开源的微信个人号接口,使用它我们可以很方便的访问我们个人微信号里的信息.itchat的github地址如下: https://github.com/littlecodersh/itc ...