作业帮 > 综合 > 作业

There is a cycle in the hierarchy!

来源:学生作业帮 编辑:灵鹊做题网作业帮 分类:综合作业 时间:2024/06/09 09:24:09
There is a cycle in the hierarchy!
List res = resourceService.findAll();
JSONArray datalist = JSONArray.fromObject(res);//这里报错there is a cycle in the hierarchy
用网上提供的方法不好使
下面是Resource属性
private Integer id;
\x05private String title;
\x05private String description;
\x05private Set roles = new HashSet();
Resource和Role有多对多的关系
Role的属性
private Integer id;
\x05private String roleName;
\x05private Set res = new HashSet();
There is a cycle in the hierarchy!
有把有关联的属性放到json数组中就可以了.因为Resource的json数组中有roles数组,而且roles的数组元素中又有Resource数组,死循环了.用JSONConfig把roles去除就可以了.