`
guduxing890
  • 浏览: 5651 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

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

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

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

    计算机组成与结构体系英文课件: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 ...

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

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

    WebServiceDemo-CXF-Main

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

    Hierarchy面板管理插件(Unity)

    在Unity游戏引擎中,"Hierarchy面板管理插件"是用来...两个插件都致力于解决Unity默认Hierarchy面板的局限性,提供更高效的场景管理体验。无论是独立开发者还是大型团队,这些插件都能显著提升Unity项目的开发效率。

    微软内部资料-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....

Global site tag (gtag.js) - Google Analytics