JSON处理Hibernate实体类net.sf.json.JSONException: There is a cycle in the hierarchy异常
来源:互联网 发布:php微信三级分销 编辑:程序博客网 时间:2024/06/06 07:12
JSON处理Hibernate实体类net.sf.json.JSONException: There is a cycle in the hierarchy异常
- 博客分类:
- 日常报错解决方案
json.netHibernateDAO
由于Hibernate中好多实体类都级联关系,也就是某个类,出现了别的类的引用对象充当属性。那么这样的话用JSON来进行处理会出现嵌套的异常:net.sf.json.JSONException: There is a cycle in the hierarchy异常。
在处理这个错误之前先看看普通的JSON处理数据示例
- <span style="font-size: medium;">TProcessInfoDAO dao = new TProcessInfoDAO();
- List<TProcessInfo> orgData = dao.findAll();
- JSONArray array=JSONArray.fromObject(orgData);
- String json=array.toString();
- System.out.println(json);
- </span>
这样的处理方式中要求TProcessInfoDAO类所有属性必须是普通属性,不包含引用按对象
如果包含引用对象一般需要做一下配置过滤引用属性,这样JSON处理就能通过:这种是不会输出引用对象的
- <span style="font-size: medium;">TProcessInfoDAO dao = new TProcessInfoDAO();
- List<TProcessInfo> orgData = dao.findAll();
- JsonConfig config = new JsonConfig();
- config.setJsonPropertyFilter(new PropertyFilter() {
- public boolean apply(Object source, String name, Object value) {
- //配置你可能出现递归的属性
- if (name.equals("TProcessInfos") || name.equals("TProcessInfo")) {
- return true;
- } else {
- return false;
- }
- }
- });
- //调用ExtHelper将你的JSONConfig传递过去
- JSONArray JsonArr=JSONArray.fromObject(orgData, config);
- String jsonstr=JsonArr.toString();
- </span>
还有一种处理方式,这种会输出引用对象
设置JSON-LIB的setCycleDetectionStrategy属性让其自己处理循环,省事但是数据过于复杂的话会引起数据溢出或者效率低下。
- <span style="font-size: medium;">TProcessInfoDAO dao = new TProcessInfoDAO();
- List<TProcessInfo> orgData = dao.findAll();
- JsonConfig config = new JsonConfig();
- config.setIgnoreDefaultExcludes(false);
- config.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
- //调用ExtHelper将你的JSONConfig传递过去
- JSONArray JsonArr=JSONArray.fromObject(orgData, config);
- String jsonstr=JsonArr.toString();
- System.out.println(jsonstr);</span>
阅读全文
0 0
- JSON处理Hibernate实体类net.sf.json.JSONException: There is a cycle in the hierarchy异常
- net.sf.json.JSONException: There is a cycle in the hierarchy异常处理
- net.sf.json.JSONException: There is a cycle in the hierarchy异常,解决方法
- net.sf.json.JSONException: There is a cycle in the hierarchy异常的解决方法
- net.sf.json.JSONException: There is a cycle in the hierarchy! 异常
- net.sf.json.JSONException: There is a cycle in the hierarchy! 异常解决
- jQuery调用JSON时,net.sf.json.JSONException: There is a cycle in the hierarchy
- jQuery调用JSON时,net.sf.json.JSONException: There is a cycle in the hierarchy
- json中net.sf.json.JSONException: There is a cycle in the hierarchy!的解决
- Json解析时出现net.sf.json.JSONException: There is a cycle in the hierarchy!42
- jQuery调用JSON时,net.sf.json.JSONException: There is a cycle in the hierarchy
- jQuery调用JSON时,net.sf.json.JSONException: There is a cycle in the hierarchy!
- json-lib 出现net.sf.json.JSONException: There is a cycle in the hierarchy异常的解决办法
- json-lib 出现net.sf.json.JSONException: There is a cycle in the hierarchy异常的解决办法
- net.sf.json.JSONException: There is a cycle in the hierarchy!
- net.sf.json.JSONException: There is a cycle in the hierarchy!
- net.sf.json.JSONException: There is a cycle in the hierarchy!
- net.sf.json.JSONException: There is a cycle in the hierarchy
- 多个版本的Python同时连接Oracle和安装cx_Oracle问题解决
- Android解析XML之DOM
- oracle中extract()函数
- SP324099: 无法完成操作--VS2015社区版无法登陆
- Python的__init__.py 文件
- JSON处理Hibernate实体类net.sf.json.JSONException: There is a cycle in the hierarchy异常
- BZOJ 4582: [Usaco2016 Open]Diamond Collector
- LeetCode-581. Shortest Unsorted Continuous Subarray (JAVA)最短未排序数组
- maven profile的使用
- VI笔记
- 【问底】徐汉彬:亿级Web系统搭建——单机到分布式集群
- iOS 通用宏定义 高效全局宏汇总
- 回归:简单一元线性回归
- From 172.25.254.48 icmp_seq=1 Destination Host Unreachable