【Other】关于There is a cycle in the hierarchy!

原因:

  父对象与子对象互相包含对方的类型的属性,造成死循环

解决方案1:

  JsonConfig config=new JsonConfig();

  config.setExcludes(new String[]{"devTask","employee","probClient"});  //传入要忽略的属性数组

  JSONObject json=JSONObject.fromObject(new Object(),config);    

  

  

  

时间: 2024-08-24 14:16:07

【Other】关于There is a cycle in the hierarchy!的相关文章

JSONException: There is a cycle in the hierarchy解决

使用hibernate容易出现该问题,主要是由于pojo类属性存在级联关系.比如说员工和部门,在员工表里面有部门属性,而在部门表里面有个员工集合,这样就存在了嵌套引用的问题了,就会抛出这个异常. 解决方法很简单,在将每个对象转为json对象的时候用setExcludes函数将级联的属性去除掉就可以了,如下面: //得到所有部门 //返回json对象字符串 public String getAllDep(){ List list = deptDAO.findAll(); JsonConfig co

atitit.解决net.sf.json.JSONException There is a cycle in the hierarchy

atitit.解决net.sf.json.JSONException There is a cycle in the hierarchy 1. 环境:使用hibernate4跟个,,要不个哪的对象系列化成个json的时候儿有这个问题了... 1 2. 原因::hb默认的lazy 方式造成的当有关联对象的时候儿... 1 3. #---解决::lazy =false  (推荐).. 1 4. 别的有以下的四个方法可以解决hibernate的序列化问题 2 5. BeanUtils.copyProp

json:There is a cycle in the hierarchy!

在使用JSONObject.fromObject的时候,出现“There is a cycle in the hierarchy”异常. 意思是出现了死循环,也就是Model之间有循环包含关系: 解决办法: 使用setCycleDetectionStrategy防止自包含 代码: JsonConfig jsonConfig = new JsonConfig(); jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT

net.sf.json.JSONException: There is a cycle in the hierarchy!错误解决方案

原因分析:在解析bean时,出现死循环调用,即:多个Bean之间出现了相互调用解决办法:过滤去掉bean中引起死循环调用的属性: [java] view plain copy List<Project> projectList = projectServices.find();  //获取数据 //自定义JsonConfig用于过滤Hibernate配置文件所产生的递归数据 JsonConfig config = new JsonConfig(); config.setExcludes(new

JSON解析关联类型发生死循环 There is a cycle in the hierarchy!

解决办法是忽略掉关联类型的数据,使用jsonConfig进行配置,代码如下: JsonConfig jsonConfig = new JsonConfig();  //建立配置文件 jsonConfig.setIgnoreDefaultExcludes(false);  //设置默认忽略 jsonConfig.setExcludes(new String[]{"glLocation"}); JSONArray jsonArray = JSONArray.fromObject(list,

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

怎么解决? 过滤掉集合属性便可 防止死循环

Json解析时出现net.sf.json.JSONException: There is a cycle in the hierarchy!

原因分析在解析bean时,出现死循环调用,即多个bean之间出现了相互调用.解决方法:将关联关系中实体对象间 的lazy属性设为false过滤掉bean中引起死循环调用的属性.(两种过滤方式) //采用数组的方式过滤关联的实体对象 JsonConfig jsonConfig = new JsonConfig(); jsonConfig.setIgnoreDefaultExcludes(false); jsonConfig.setCycleDetectionStrategy(CycleDetect

json-lib-2.4-jdk15.jar 报错 net.sf.json.JSONException: There is a cycle in the hierarchy!错误解决方案(Hibernate)

使用hibernate容易出现该问题,主要是由于pojo类属性存在级联关系.比如说员工和部门,在员工表里面有部门属性,而在部门表里面有个员工集合,这样就存在了嵌套引用的问题了,就会抛出这个异常. 解决方法很简单,在将每个对象转为json对象的时候用setExcludes函数将级联的属性去除掉就可以了,如下面: 比如CityVo  里面有关联属性 ProvinceVo province 以及 地区属性 Set<DistrictVo> districtList 使用hibernate 查询所有的c

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

使用hibernate容易出现该问题,主要是由于pojo类属性存在级联关系.比如说员工和部门,在员工表里面有部门属性,而在部门表里面有个员工集合,这样就存在了嵌套引用的问题了,就会抛出这个异常. 解决方法很简单,在将每个对象转为json对象的时候用setExcludes函数将级联的属性去除掉就可以了,如下面: //得到所有部门     //返回json对象字符串     public String getAllDep(){         List list = deptDAO.findAll(