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錯誤,以下圖:java

 

參數使用JSON格式,POST請求,以下圖:sql

 

createTime變量使用了字符串類型,接口接收參數後將該字符串轉爲日期時,發生錯誤,項目中使用fastjson來處理json數據。json

此問題解決方法測試

在接收參數實體類的createtime字段添加JsonFormat註解code

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

以下圖:orm

 

項目重啓,再次請求,若是以下:blog

 

請求成功,若是使用了Timestamp類型來接口,有可能會報下面的異常:接口

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

這時,使用上面的方法也可解決問題。ast

相關文章
相關標籤/搜索