This repository has been archived by the owner on Oct 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
JSON.toJSONString(obj, SerializerFeature.PrettyFormat)导致循环引用path异常 #3672
Milestone
Comments
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.google.common.collect.Lists;
import lombok.Data;
import org.junit.Test;
import java.util.ArrayList;
public class Issue3672 {
@Test
public void test1() {
Issue3672Root root = new Issue3672Root();
Issue3672A a = new Issue3672A();
Issue3672B b = new Issue3672B();
Issue3672C c = new Issue3672C();
Issue3672D d = new Issue3672D();
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));
}
@Data
private class Issue3672Root {
private Issue3672A a;
}
@Data
private class Issue3672A {
private Object[] b;
}
@Data
private class Issue3672B {
private Issue3672C c;
}
@Data
private class Issue3672C {
private Issue3672D d;
}
@Data
private class Issue3672D {
private ArrayList<Issue3672C> e;
}
} 运行输出如下
复现如上 |
PS:
to
输出就不会有null了 |
Certseeds
added a commit
to Certseeds/fastjson
that referenced
this issue
Mar 9, 2021
… transfer array id to write(), so it will appear null. <type>: - [x] Bug fix - [x] This change requires a documentation update Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
Closed
Certseeds
added a commit
to Certseeds/fastjson
that referenced
this issue
Jul 10, 2021
</subject> Branch: issue3672-2nd <type>: - [ ] Bug fix - [ ] Bug fix (Test) - [ ] New feature - [ ] Breaking change - [ ] Documentation update - [ ] This change requires a documentation update <body> <footer> Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
Certseeds
added a commit
to Certseeds/fastjson
that referenced
this issue
Jun 26, 2022
</subject> Branch: issue3672-2nd <type>: - [ ] Bug fix - [ ] Bug fix (Test) - [ ] New feature - [ ] Breaking change - [ ] Documentation update - [ ] This change requires a documentation update <body> <footer> Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
第一个输出: { "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"}
The text was updated successfully, but these errors were encountered: