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

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

    博客分类:
  • json
阅读更多

       如果json解析的数据间存在级联关系,就会互相嵌套引用,特别在使用hibernate时容易出现这种异常,抛出net.sf.json.JSONException: There is a cycle in the hierarchy异常。

解决方法:

      1、设置JSON-LIB的Excludes让其过滤掉引起循环的字段。

 

JsonConfig config = new JsonConfig(); 
config.setIgnoreDefaultExcludes(false); 
config.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT); 
config.registerJsonValueProcessor(Date.class,new DateJsonValueProcessor("yyyy-MM-dd")); 
//只要设置这个数组,指定过滤掉哪些字段
config.setExcludes(new String[]{ "aaa", "bbb", "ccc", "ddd" }); 

       2、设置JSON-LIB的setCycleDetectionStrategy属性让其自己处理循环,缺点:当数据过于复杂时会引起数据溢出或者效率低下

 

JsonConfig config = new JsonConfig(); 
config.setIgnoreDefaultExcludes(false); 
config.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT); 
config.registerJsonValueProcessor(Date.class,new DateJsonValueProcessor("yyyy-MM-dd")); 

 

分享到:
评论

相关推荐

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

    BIG文件编辑器

    The Lord of the Rings(tm), The Battle for Middle-earth(tm) is a trademark or registered trademark of Electronic Arts in the USA and/or other countries. All rights reserved. LucasArts, the LucasArts ...

    FastReport_.NET_Resigned_NetFx4_Bins_2019.3.20.rar

    * updated a polygon object: now the polygon toolbar is displayed not near to the object, but in the main toolbar and in ribbon; polygon modes are changed, new modes allow editing and adding curves > ...

    win 3.11 for workgroup tcpip支持

    conditions is to put a #PRE against the name in the LMHOSTS file. This causes the name to be stored in the name cache when the machine is first initialized, so the name gets resolved without the ...

    Git-2.21.0-64-bit.zip

    value for the HEAD symbolic ref when the namespace feature is in use, which has been corrected. * "git am -i --resolved" segfaulted after trying to see a commit as if it were a tree, which has ...

    前端项目-d3-hierarchy.zip

    在“d3-hierarchy-master”这个项目中,重点在于层次数据(Hierarchy Data)的可视化。层次数据通常表现为树形结构,例如组织架构、文件系统或者生物学的物种分类等。D3提供了hierarchy模块,专门处理这类数据,可以...

    CScrollHelper CScrollWnd

    Implementing standard scrolling behavior for a custom CWnd or CDialog-derived class using MFC is fairly non... No change in your inheritance hierarchy is required to use the helper class (CScrollHelper).

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

    QHierarchy 4.2 最新版Unity插件

    - Displaying the list of GameObjects in the form of a tree - Option to add right indent (useful if you use other plugins that add another icons to the hierarchy window) - Any feature can be disabled ...

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

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

    django-admin-lightweight-date-hierarchy:带有零查询的Django admin date_hierarchy

    【django-admin-lightweight-date-hierarchy】是一个针对Django管理后台(django-admin)的优化扩展,主要目的是提升日期层次结构(date_hierarchy)功能的性能。在默认情况下,Django的date_hierarchy功能在处理...

    Pro-Deep-Learning-with-TensorFlow.pdf

    Deep learning is a branch of machine learning where you model the world in terms of a hierarchy of concepts. This pattern of learning is similar to the way a human brain learns, and it allows ...

    S7-400 CPU Specifications Manual .pdf

    The manual is a comprehensive guide for engineers, technicians, and maintenance personnel involved in the planning, commissioning, and maintenance of S7-400 systems. It is essential reading for ...

Global site tag (gtag.js) - Google Analytics