zoukankan      html  css  js  c++  java
  • 【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);    

    解决方案2:

     

      

    JsonConfig config=new JsonConfig();
      config.setJsonPropertyFilter(new PropertyFilter(){
      
    //需要过滤的属性
       public boolean apply(Object source, String name, Object value) {   //source :源对象   name:属性名 value 属性值 
        if(source instanceof Employee&&(name.equals("devTasks")||name.equals("probClients")||name.equals("role")))
         return true;
        if(source instanceof Role&&(name.equals("actions")||name.equals("emps")))
         return true;
        if(source instanceof DevTask&&(name.equals("devTaskPlans")))
         return true;
        if(source instanceof ProbClient&&(name.equals("devTasks")))
         return true;
        return false;
       }
       
      });
      Map<String,Object> m=new HashMap<String,Object>();
      m.put("index", index);
      m.put("size",size );
      m.put("total",total );
      m.put("pages",pages );
      m.put("devList",devList );
      //m.put("probClient",probClient );
      JSONObject json=JSONObject.fromObject(m,config);
    

      

      

      

  • 相关阅读:
    Leetcode Minimum Path Sum
    Leetcode House Robber II
    洛谷 P5375 【[THUPC2019]组合数据结构问题】题解
    洛谷 P1855 【榨取kkksc03】题解
    CF1173A 【Nauuo and Votes】题解
    [NOIP2018D1T1][NOIP2013D1T1][Luogu P5019]铺设道路 题解
    [BZOJ1083][SCOI2005]繁忙的都市 题解
    统计自己洛谷AC题目爬虫
    CF43A Football 题解
    SP2 PRIME1
  • 原文地址:https://www.cnblogs.com/LightChan/p/7291389.html
Copyright © 2011-2022 走看看