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. D2欧拉路,拓扑排序,和差分约束

    第一题:太鼓达人:BZOJ3033 题意:给出k,求一个最长的M位01串,使其从每一个位置向后走k个得到 的M个k位01串互不相同(最后一个和第一个相邻,即是一个环).输出 字典序最小的答案. 2 ≤ ...

  2. HTML5常用API

    .Fullscreen 该API允许开发者以编程方式将Web应用程序全屏运行,使Web应用程序更像本地应用程序. .Page Visibility 该API可以用来检测页面对于用户的可见性,即返回用户 ...

  3. IdentityServer4支持的授权类型以及组合

    支持的授权类型: implicit hybrid authorization_code client_credentials password 支持的组合: implicit implicit,cli ...

  4. 1_Linux概述

    linux就是一套操作系统 //系统调用与内核如果能够参考硬件的功能函数并修改你的操作系统程序代码,那经过改版后的操作系统就能够在另一个硬件平台上面运行了,这个操作通常被称为"软件移植&qu ...

  5. java笔记 -- java运算

    运算符: 算术运算符: 加减乘除求余 + , - , * , / , % 当参与/运算的两个操作数都是整数时, 表示整数除法, 否则表示浮点除法. 例: 15 / 2 = 7; 15 % 2 = 1; ...

  6. ES6的小知识(后半部分)

    一.iterator和for-of循环 在js里有数组和对象,es6又新出现了set和map这样js就有了四种数据集合,这样可以组合使用他们,比如数组里拥有对象,set等,这样就需要一个统一的 接口机 ...

  7. elementUI

    开始学习elementUI了. 怎么可以快速的学习一个UI框架,是我们的值得思考的事情. 博客,重点,记忆. <el-button @click="visible = true&quo ...

  8. SQL查询日期格式化

    MARK一下 方便以后自己查阅 举例如下: getdate() 可以替换成日期类型字段 select Convert(varchar(10),getdate(),120) 2006-05-12sele ...

  9. The `android.dexOptions.incremental` property is deprecated and it has no effect on the build process.

    编译报错:The android.dexOptions.incremental property is deprecated and it has no effect on the build pro ...

  10. 整理整理Linux命令

    自用.. 1. 查看当前文件目录下,所有文件消耗的磁盘容量 du -h ./ 2. 系统中文件的使用情况 df -h 和du -h显示磁盘大小不一致可能是因为使用rm删除时,文件存在link,没有删除 ...