问题描述
使用带 filter 参数的 JSON.toJSONString 方法,同时指定 Feature.ReferenceDetection Feature参数
转出的 json 自引用属性后面缺少冒号“:” ,格式错误
环境信息
请填写以下信息:
- OS信息: Win10 4Core 16 GB
- JDK信息: Openjdk 1.8.0_312
- 版本信息:Fastjson2 2.0.51
重现步骤
见代码
- 使用带 filter 参数的
JSON.toJSONString 方法,同时指定 Feature.ReferenceDetection Feature参数
- 输入 任意带循环引用 的数据
- 出现 转出的 json 自引用属性后面缺少冒号“:” ,格式错误
Map<String, Object> map = new HashMap<>();
map.put("k", "v");
map.put("selfRef", map);
// 无 filter 参数的 toJSONString
String json = com.alibaba.fastjson2.JSON.toJSONString(map, Feature.ReferenceDetection);
System.out.println(json); // 输出:{"selfRef":{"$ref":".."},"k":"v"} ,结果正确
PropertyPreFilter propertyJsonFilter = (serializer, source, property) -> true;
// 带 filter 参数的 toJSONString
String badJson = com.alibaba.fastjson2.JSON.toJSONString(map, propertyJsonFilter, Feature.ReferenceDetection);
System.out.println(badJson); // 输出:{"selfRef"{"$ref":"$"},"k":"v"} ,自引用属性后面少了冒号“:”
期待的正确结果
输出自引用属性后不缺少冒号“:”的正确格式 json 字符串
问题描述
使用带 filter 参数的
JSON.toJSONString方法,同时指定 Feature.ReferenceDetection Feature参数转出的 json 自引用属性后面缺少冒号“:” ,格式错误
环境信息
请填写以下信息:
重现步骤
见代码
JSON.toJSONString方法,同时指定 Feature.ReferenceDetection Feature参数期待的正确结果
输出自引用属性后不缺少冒号“:”的正确格式 json 字符串