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);
    

      

      

      

  • 相关阅读:
    CYPEESS USB3.0程序解读之---同步FIFO(slaveFifoSync)
    CYPEESS USB3.0程序解读之---GPIO
    USB 3.0 开发要点
    关于const声明一些东西
    __attribute__ 你知多少?
    char、signed char、unsigned char的区别总结。
    CentOS7安装配置SAMBA服务器
    linux版本FTP下载
    2021年1月29日
    2021年11月28日
  • 原文地址:https://www.cnblogs.com/LightChan/p/7291389.html
Copyright © 2011-2022 走看看