There is a cycle in the hierarchy解决办法

来源:互联网 发布:nginx pagespeed 配置 编辑:程序博客网 时间:2024/05/17 04:34

There is a cycle in the hierarchy解决办法:

错误原因:将对象转换为json串时的错误,可能原因是存在级联(及树结构)或者对象间的互相调用。

解决方法:去掉级联或者互相调用而导致干扰的对象,例如:

public void sendUser(User user) {   JsonConfig jsonConfig = new JsonConfig();  //建立配置文件   jsonConfig.setExcludes(new String[]{"company","role","office","roleList","vacation","moreWorkTime"});  //此处是亮点,只要将所需忽略字段加到数组中即可   jsonConfig.setIgnoreDefaultExcludes(false);  //设置默认忽略   jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);   JSONObject json = JSONObject.fromObject(user,jsonConfig);   String jsonString = json.toString();}

原创粉丝点击