zoukankan      html  css  js  c++  java
  • fastjson把对象转化成json避免$ref

    1. DisableCircularReferenceDetect来禁止循环引用检测:

    2. JSON.toJSONString(..., SerializerFeature.DisableCircularReferenceDetect)

    3.项目中遇到问题的源代码:

    //        查询所有的订单
            @ResponseBody
            @RequestMapping("queryAllOrderList")
            public void queryAllOrderList(HttpServletResponse response){
                List<OrderList> orderLi=orderService.queryAllOrders()
                jo.put("total", orderLi.size());
                jo.put("rows", orderLi);
                try {
                    response.getWriter().append(JSON.toJSONString(jo, SerializerFeature.DisableCircularReferenceDetect));
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

    3. 引用是通过"$ref"来表示的

    引用描述
    "$ref":".." 上一级
    "$ref":"@" 当前对象,也就是自引用
    "$ref":"$" 根对象
    "$ref":"$.children.0" 基于路径的引用,相当于 root.getChildren().get(0)
  • 相关阅读:
    IllegalStateException
    TimeUnit简析
    Cron表达式
    任务调度之Timer与TimerTask配合
    Executor简析
    this逃逸
    SQL、SQL Server、MySQL与Oracle
    数据库与实例
    vw 、vh、vmin 、vmax
    逻辑(内存)分页与物理分页
  • 原文地址:https://www.cnblogs.com/514929hgy/p/7399267.html
Copyright © 2011-2022 走看看