我是靠谱客的博主 昏睡外套,这篇文章主要介绍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.LocalDateTime` from String错误,如下图:

 

参数使用JSON格式,POST请求,如下图:

 

createTime变量使用了字符串类型,接口接收参数后将该字符串转为日期时,发生错误,项目中使用fastjson来处理json数据。

此问题解决方法

在接收参数实体类的createtime字段添加JsonFormat注解

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm:ss")

如下图:

 

项目重启,再次请求,如果如下:

 

请求成功,如果使用了Timestamp类型来接口,有可能会报下面的异常:

JSON parse error: Can not deserialize value of type java.sql.Timestamp from String

这时,使用上面的方法也可解决问题。

 

转载于:https://www.cnblogs.com/codecat/p/10845797.html

最后

以上就是昏睡外套最近收集整理的关于JSON parse error: Cannot deserialize value of type `java.time.LocalDateTime` from String的全部内容,更多相关JSON内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(106)

评论列表共有 0 条评论

立即
投稿
返回
顶部