[BUG] JSONWriter.Feature.ReferenceDetection重复引用序列化错误
- Dominant language
- Java
- Stars
- 4.4k
- Forks
- 613
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 6
Description
### 问题描述
在使用fastjson替换jackson的全局处理
配置如下
FastJsonConfig config = new FastJsonConfig();
config.setWriterFeatures(
JSONWriter.Feature.ReferenceDetection, // 处理循环引用和树形结构的处理
JSONWriter.Feature.WriteEnumsUsingName, // 序列化enum使用name
JSONWriter.Feature.BrowserCompatible, // 兼容IE6
JSONWriter.Feature.BrowserSecure // 浏览器安全,将会’<’ ‘>’ ‘(’ ')'字符做转义输出
);
处理过程中在重复引用的处理上会出现,key丢失的情况,如下:
"companyCorporation": "黄明望"{
"$ref": "$.result.data[0].contacts"
}
正确结果应该是
"companyCorporation": "黄明望",
"contacts":{
"$ref": "$.result.data[0].contacts"
}
### 环境信息
*请填写以下信息:*
- OS信息: [e.g.:CentOS 8.4.2105 4Core 3.10GHz 16 GB]
- JDK信息: [e.g.:Openjdk 1.8.0_312]
- 版本信息:[e.g.:Fastjson2 2.0.49]
Contributor guide
Research direction
Start by reproducing the duplicate-reference case with JSONWriter.Feature.ReferenceDetection and the listed writer features; no source file or test is named in the issue. Trace the serialization path that emits the $ref object and add a regression test showing that the contacts key is retained alongside the reference.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend-api-design
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100