解决: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方法,解决方式跟上面的错误一样。

发布了30 篇原创文章 · 获赞 15 · 访问量 2936

猜你喜欢

转载自blog.csdn.net/qq_40891009/article/details/102673358