解決:Could not write JSON: No serializer found for class *** and no properties錯誤


場景:使用RestController或者Controller注解將查詢的實體轉換成json字符串時報錯。

原因:需要轉換的對應實體類的屬性缺少:getter和setter方法,導致將實體類轉換的json格式類無法讀取對應的屬性從而報錯。

解決方法:在需要轉換的實體類中給屬性加上getter和setter方法(或者使用:lombok插件給實體類加上getter和setter注解)。

錯誤信息為:Request processing failed;nested exception is java.lang.IllegalArgumentException;No converter found for return value of type...的原因同樣是實體類缺少getter和setter方法,解決方法如上。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM