net.sf.json.JSONException: There is a cycle in the hierarchy! 解决

版权声明:转载请标明出处 https://blog.csdn.net/u013189824/article/details/85016323

当我们使用JPA创建实体有多对多(@OneToMany),一对多(@OneToMany)的关系时,利用net.sf.json.JSONObject.fromObject(实体或存储实体的集合)时,报错:

net.sf.json.JSONException: There is a cycle in the hierarchy! 

这时需要我们对JSONObject(或JSONArray)类在fromObject时设置CycleDetectionStrategy.LENIENT策略:

JsonConfig jsonConfig = new JsonConfig();
jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
JSONArray json = JSONArray.fromObject(list<Entity>,jsonConfig);

CycleDetectionStrategy.LENIENT顾名思义:循环检测策略.宽大处理。

猜你喜欢

转载自blog.csdn.net/u013189824/article/details/85016323