We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
在使用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" }
@Data public class ClueListInfo implements Serializable { private static final long serialVersionUID = 8170584149020082450L; private Long clueId; private String name; private List<ContactInfo> contacts; } @Data public class ContactInfo implements Serializable { private static final long serialVersionUID = -5313505758293424804L; private Long id; private String name; } public class Issue2687 { @Test void test(){ ClueListInfo info1 = new ClueListInfo(); info1.setClueId(1L); info1.setName("Clue 01"); ClueListInfo info2 = new ClueListInfo(); info2.setClueId(2L); info2.setName("Clue 02"); ContactInfo contactInfo = new ContactInfo(); contactInfo.setId(1L); contactInfo.setName("contact"); ArrayList<ContactInfo> contacts = Lists.newArrayList(contactInfo); info1.setContacts(contacts); info2.setContacts(contacts); List infos = Lists.newArrayList(info1,info2); String jsonString = JSON.toJSONString(infos, JSONWriter.Feature.ReferenceDetection); System.out.println(jsonString); } }
[{"clueId":1,"contacts":[{"id":1,"name":"contact"}],"name":"Clue 01"},{"clueId":2,"contacts":{"$ref":"$[0].contacts"},"name":"Clue 02"}]
[{"clueId":1,"contacts":[{"id":1,"name":"contact"}],"name":"Clue 01"},{"clueId":2{"$ref":"$[0].contacts"},"name":"Clue 02"}]
The text was updated successfully, but these errors were encountered:
fix add field name write for list value, for issue #2712
9b9de40
Fix 2712 (#2718)
5b1e892
* fix add field name write for list value, for issue #2712
https://github.com/alibaba/fastjson2/releases/tag/2.0.52 问题已修复,请用新版本
Sorry, something went wrong.
yanxutao89
No branches or pull requests
问题描述
在使用fastjson替换jackson的全局处理
配置如下
处理过程中在重复引用的处理上会出现,key丢失的情况,如下:
"companyCorporation": "黄明望"{
"$ref": "$.result.data[0].contacts"
}
正确结果应该是
"companyCorporation": "黄明望",
"contacts":{
"$ref": "$.result.data[0].contacts"
}
复现场景
需要的结果
实际结果
The text was updated successfully, but these errors were encountered: