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