`
ouxitao
  • 浏览: 8644 次
文章分类
社区版块
存档分类
最新评论

There is a cycle in the hierarchy!

阅读更多

在做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)  

 

 

分享到:
评论

相关推荐

    json-lib出现There is a cycle in the hierarchy解决办法

    如果需要解析的数据间存在级联关系,而互相嵌套引用,在hibernate中极容易嵌套而抛出net.sf.json.JSONException: There is a cycle in the hierarchy异常。

    S2S3H3整合以及泛型Dao与Service封装

    并且对Dao和Service进行了封装,内含.jar包,并且解决了一对多双向关联的could not initialize proxy - no Session错误,同时解决了……invoked on net.sf.json.JSONException: There is a cycle in the hierarchy!...

    计算机组成与结构体系英文课件:Chapter 8 – The Memory System - 2

    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 ...

    A consistency improving method in the analytic hierarchy process based on directed circuit analysis

    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 ...

    Android View Hierarchy,解决View Hierarchy不能启动

    解决这个启动 View Hierarchy时的这个bug: hierarchy viewer unable to debug device

    The Elements of Computing Systems

    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

    【WebServiceDemo-CXF-Main】是一个使用Apache CXF框架通过主方法(Main)来发布的Web服务示例。在本文中,我们将深入探讨Web服务、Apache CXF框架以及如何通过Java的main方法启动Web服务。 首先,让我们理解Web...

    Hierarchical_State_Machine 源代码

    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 ...

    微软内部资料-SQL性能优化3

    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 ...

    Deep learning

    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....

    deep learning

    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

    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....

Global site tag (gtag.js) - Google Analytics