在做Hibernate 映射对象转换json 的时候 遇到如下异常
net.sf.json.JSONException: There is a cycle in the hierarchy! at net.sf.json.util.CycleDetectionStrategy$StrictCycleDetectionStrategy.handleRepeatedReferenceAsObject(CycleDetectionStrategy.java:97) at net.sf.json.JSONObject._fromBean(JSONObject.java:859) at net.sf.json.JSONObject.fromObject(JSONObject.java:194) at net.sf.json.JSONObject._processValue(JSONObject.java:2793) at net.sf.json.JSONObject._setInternal(JSONObject.java:2817) at net.sf.json.JSONObject.setValue(JSONObject.java:1527) at net.sf.json.JSONObject._fromBean(JSONObject.java:946) at net.sf.json.JSONObject.fromObject(JSONObject.java:194)
解决方法
JsonConfig jsonConfig = new JsonConfig(); jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT); // 自动为我排除circle。 jsonConfig.setExcludes(new String[] { "user" }); // 设置转换中忽略的属性 JSONArray.fromObject(sourceList,jsonConfig)
相关推荐
如果需要解析的数据间存在级联关系,而互相嵌套引用,在hibernate中极容易嵌套而抛出net.sf.json.JSONException: There is a cycle in the hierarchy异常。
并且对Dao和Service进行了封装,内含.jar包,并且解决了一对多双向关联的could not initialize proxy - no Session错误,同时解决了……invoked on net.sf.json.JSONException: There is a cycle in the hierarchy!...
Memory Hierarchy is a design strategy implemented to bridge the gap between the Central Processing Unit (CPU) and the various types of memory, which have differing speed, capacity, and cost ...
Test of consistency is critical for the AHP methodology. When a pairwise comparison matrix (PCM) fails the consistency test, the decision maker (DM) needs to make revisions. The state of the art ...
解决这个启动 View Hierarchy时的这个bug: hierarchy viewer unable to debug device
the best way to understand how computers work is to build one from scratch, and this textbook leads students through twelve chapters and projects that gradually build a basic hardware platform and a ...
【WebServiceDemo-CXF-Main】是一个使用Apache CXF框架通过主方法(Main)来发布的Web服务示例。在本文中,我们将深入探讨Web服务、Apache CXF框架以及如何通过Java的main方法启动Web服务。 首先,让我们理解Web...
Even when the actual handling differs, there is still some commonality. Hierarchical state machine design captures the commonality by organizing the states as a hierarchy. The states at the higher ...
An intent lock indicates that SQL Server wants to acquire a shared (S) lock or exclusive (X) lock on some of the resources lower down in the hierarchy. For example, a shared intent lock placed at the ...
co-founder and CEO of Tesla and SpaceX, Deep learning is a form of machine learning that enables computers to learn from experience and understand the world in terms of a hierarchy of concepts....
co-founder and CEO of Tesla and SpaceX, Deep learning is a form of machine learning that enables computers to learn from experience and understand the world in terms of a hierarchy of concepts....
The Application of AHP+LP in the Evaluation and Selection of Suppliers,BAI He-song,,This paper introduces the Supplier Relationship Management and the evaluation and selection of suppliers....