`
yxgyh
  • 浏览: 275527 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

There is a cycle in the hierarchy!

    博客分类:
  • JAVA
阅读更多

在开发过程中遇到了一个JSON-LIB和Hibernate有关的问题:

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

因为Hibernate中设置了自身关联:

 <set name="areas" inverse="true">
         <key>
          <column name="mid" not-null="true" />
         </key>
         <one-to-many class="Area"/>
</set>

 

//设置自身关联的组对象

public class Map {
    private Integer mid;
    private Integer x;
    private Integer y;
    private String url;
    private Set<Area> areas = new HashSet<Area>();

 

通过JSON-LIB来过滤关联的集合属性,代码如下:

JsonConfig config = new JsonConfig();
config.setJsonPropertyFilter(new PropertyFilter(){
    public boolean apply(Object source, String name, Object value) {
        if(name.equals("areas")) { //要过滤的areas ,Map对象中的
            return true;
        } else {
            return false;
        }
    }
});                
JSONObject json = JSONObject.fromObject( ma , config); /// ma 为要转成json的 Map 对象

 

http://www.cnblogs.com/ksyou/archive/2009/05/31/1493061.html

分享到:
评论

相关推荐

    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