8000 JSON.toJSONString(obj, SerializerFeature.PrettyFormat)导致循环引用path异常 · Issue #3672 · alibaba/fastjson · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Oct 23, 2024. It is now read-only.
This repository was archived by the owner on Oct 23, 2024. It is now read-only.
JSON.toJSONString(obj, SerializerFeature.PrettyFormat)导致循环引用path异常 #3672
@txgj

Description

@txgj
    IssueCR root = new IssueCR();
    IssueCA a = new IssueCA();
    IssueCB b= new IssueCB();
    IssueCC c = new IssueCC();
    IssueCD d = new IssueCD();

    root.setA(a);
    a.setB(Lists.newArrayList(b).toArray());
    b.setC(c);
    c.setD(d);
    d.setE(Lists.newArrayList(c));


    System.out.println(JSON.toJSONString(root, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue));
    System.out.println(JSON.toJSONString(root));

第一个输出: { "a":{ "b":[ { "c":{ "d":{ "e":[ {"$ref":"$.a.b.null.c"} ] } } } ] } }

第二个输出: {"a":{"b":[{"c":{"d":{"e":[{"$ref":"$.a.b[0].c"}]}}}]}}

因为使用SerializerFeature.PrettyFormat时,在处理数组的序列化时,走了不同的逻辑,导致出现{"$ref":"$.a.b.null.c"}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0