实体Menu有两个属性
private Set roleMenus = new HashSet(0);
private Set newsMenus = new HashSet(0);
因此在查询出List<Menu> menuList,并转换成json数据时,
这两个属性互相引用造成了死循环,于是报错:There is a cycle in the hierarchy!
解决办法:
JsonConfig config = new JsonConfig();
config.setExcludes(new String[]{"roleMenus","newsMenus"();
String str = JSONArray.fromObject(menuList,config).toString();

本文讨论了在使用JSON序列化时遇到的实体类属性互相引用导致的死循环问题,并提供了通过配置排除指定属性的方法来解决此问题的解决方案。
520

被折叠的 条评论
为什么被折叠?



