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错误,记录如下:

 

Postman参数如图

 

 

 接收对象参数如图:

 

 

 

报错:

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

如图:

 

 

 

解决方法

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

@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", locale = "zh", timezone = "GMT+8")

如图:

 

 

注意

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

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

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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM