Skip to content
New issue

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

[BUG] 带 filter 和 Feature 参数的 JSON.toJSONString 方法,指定任意filter参数 和 Feature.ReferenceDetection Feature参数,转出的 json 自引用属性后面缺少冒号“:” ,格式错误 #2678

Closed
anyxgit opened this issue Jun 7, 2024 · 1 comment
Assignees
Labels
bug Something isn't working fixed
Milestone

Comments

@anyxgit
Copy link

anyxgit commented Jun 7, 2024

问题描述

使用带 filter 参数的 JSON.toJSONString 方法,同时指定 Feature.ReferenceDetection Feature参数
转出的 json 自引用属性后面缺少冒号“:” ,格式错误

环境信息

请填写以下信息:

  • OS信息: Win10 4Core 16 GB
  • JDK信息: Openjdk 1.8.0_312
  • 版本信息:Fastjson2 2.0.51

重现步骤

见代码

  1. 使用带 filter 参数的 JSON.toJSONString 方法,同时指定 Feature.ReferenceDetection Feature参数
  2. 输入 任意带循环引用 的数据
  3. 出现 转出的 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 字符串

@anyxgit anyxgit added the bug Something isn't working label Jun 7, 2024
@yanxutao89 yanxutao89 self-assigned this Jun 7, 2024
@wenshao wenshao added this to the 2.0.52 milestone Jun 7, 2024
@wenshao wenshao added the fixed label Jun 7, 2024
@wenshao
Copy link
Member

wenshao commented Jul 14, 2024

https://github.com/alibaba/fastjson2/releases/tag/2.0.52
问题已修复,请用新版本

@wenshao wenshao closed this as completed Jul 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed
Projects
None yet
Development

No branches or pull requests

3 participants