zoukankan      html  css  js  c++  java
  • net.sf.json.JSONException: There is a cycle in the hierarchy!

    项目中使用了AJAX技术,JAR包为:json-lib.jar, 在开发过程中遇到了一个JSON-LIB和Hibernate有关的问题:

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

     at net.sf.json.util.CycleDetectionStrategy$StrictCycleDetectionStrategy.handleRepeatedReferenceAsObject(CycleDetectionStrategy.

    主外键关联,产生循环错误

    需设置过滤,去掉关联

    Java

        public ModelAndView getRooms(HttpServletResponse response,@PathVariable Long hotelsid){
            List<Room> roomList=roomService.findByHotelsid(hotelsid);
            JsonConfig jsonConfig = new JsonConfig();
            jsonConfig.setJsonPropertyFilter(new net.sf.json.util.PropertyFilter(){
                @Override
                public boolean apply(Object source, String name, Object value) {
                    if(name.equals("hotels")){
                        return true;
                    }else{
                    return false;
                    }
                }});
            
            JSONArray json=JSONArray.fromObject(roomList,jsonConfig);
            
            try {
                PrintWriter out=response.getWriter();
                out.println(json.toString());
                out.flush();
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            
            return null;
        }
  • 相关阅读:
    P2351 [SDOI2012]吊灯
    洛谷P1450 [HAOI2008]硬币购物 背包+容斥
    P5110 块速递推-光速幂、斐波那契数列通项
    AT2304 Cleaning
    CSP-S 2020
    CF487E Tourists
    P4334 [COI2007] Policija
    动态逆序对专练
    CF437D The Child and Zoo
    CF1032G Chattering
  • 原文地址:https://www.cnblogs.com/archie2010/p/1945178.html
Copyright © 2011-2022 走看看