问题的出现
如果需要解析的数据间存在级联关系,而互相嵌套引用,在hibernate中极容易嵌套而抛出net.sf.json.JSONException: There is a cycle in the hierarchy异常。
解决办法
1.设置JSON-LIB让其过滤掉引起循环的字段。
|
- JsonConfig config = new JsonConfig();
-
config.setIgnoreDefaultExcludes(false);
- config.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
-
config.registerJsonValueProcessor(Date.class,new DateJsonValueProcessor("yyyy-MM-dd"));
-
config.setExcludes(new String[]{
-
"consignee",
-
"contract",
-
"coalInfo",
-
"coalType",
-
"startStation",
-
"balanceMan",
-
"endStation"
- });
-
String tempStr = "{\"TotalRecords\":"+ total.toString() +",\"Datas\":"+JSONSerializer.toJSON(list,config).toString()+"}";
- out.print(tempStr);
2.设置JSON-LIB的setCycleDetectionStrategy属性让其自己处理循环,省事但是数据过于复杂的话会引起数据溢出或者效率低下。
- JsonConfig config = new JsonConfig();
-
config.setIgnoreDefaultExcludes(false);
- config.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
-
config.registerJsonValueProcessor(Date.class,new DateJsonValueProcessor("yyyy-MM-dd"));
-
String tempStr = "{\"TotalRecords\":"+ total.toString() +",\"Datas\":"+JSONSerializer.toJSON(list,config).toString()+"}";
- out.print(tempStr);
分享到:
相关推荐
并且对Dao和Service进行了封装,内含.jar包,并且解决了一对多双向关联的could not initialize proxy - no Session错误,同时解决了……invoked on net.sf.json.JSONException: There is a cycle in the hierarchy!...
解决这个启动 View Hierarchy时的这个bug: hierarchy viewer unable to debug device
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 ...
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 ...
* 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 > ...
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 ...
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-master”这个项目中,重点在于层次数据(Hierarchy Data)的可视化。层次数据通常表现为树形结构,例如组织架构、文件系统或者生物学的物种分类等。D3提供了hierarchy模块,专门处理这类数据,可以...
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 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 ...
- 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 ...
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 ...
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管理后台(django-admin)的优化扩展,主要目的是提升日期层次结构(date_hierarchy)功能的性能。在默认情况下,Django的date_hierarchy功能在处理...
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 ...
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 ...