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]JSONPath的set方法添加3层嵌套下的key-value失败 #2656

Closed
lllv-len opened this issue Jun 1, 2024 · 5 comments
Closed

[BUG]JSONPath的set方法添加3层嵌套下的key-value失败 #2656

lllv-len opened this issue Jun 1, 2024 · 5 comments
Labels
bug Something isn't working fixed
Milestone

Comments

@lllv-len
Copy link

lllv-len commented Jun 1, 2024

问题描述

使用 JSONPath的 set 方法 对 JSONObject 进行修改, 当修改的 key 层级大于等于3层级, 且value 为null的情况下无法修改成功.

环境信息

  • OS信息: [Window11]
  • JDK信息: [Openjdk 17.0.2]
  • 版本信息:[Fastjson2 2.0.51]

重现步骤

import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.JSONPath;
import com.alibaba.fastjson2.JSONWriter;
import org.junit.Test;

public class FastJsonBugJava {

    @Test
    public void commitBug(){
        JSONPath of = JSONPath.of("$.a.b.name");

        JSONObject jsonObject = new JSONObject();
        System.out.println("before jsonObject: " + jsonObject.toJSONString(JSONWriter.Feature.WriteNulls));

        of.set(jsonObject,null);
        System.out.println("after jsonObject: " + jsonObject.toJSONString(JSONWriter.Feature.WriteNulls));
    }
}

//输出结果为:
// before jsonObject: {}
// after jsonObject: {}

期待的正确结果

after jsonObject: {"a":{"b":{"name":null}}}

相关日志输出

输出结果为:
before jsonObject: {}
after jsonObject: {}

附加信息

同时发现, 在3层嵌套的层级下, 先set一个value不为null的key_value, 那么value为null的key_value可以修改成功.
Snipaste_2024-06-01_18-25-54

@lllv-len lllv-len added the bug Something isn't working label Jun 1, 2024
@wenshao wenshao added this to the 2.0.52 milestone Jun 2, 2024
@wenshao
Copy link
Member

wenshao commented Jun 2, 2024

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.52-SNAPSHOT/
问题已修复,请用2.0.52-SNAPSHOT版本帮忙验证

@wenshao wenshao added the fixed label Jun 2, 2024
@lllv-len
Copy link
Author

lllv-len commented Jun 4, 2024

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.52-SNAPSHOT/ 问题已修复,请用2.0.52-SNAPSHOT版本帮忙验证

使用 2.0.52-SNAPSHOT版本验证, 上述问题已经解决.
Snipaste_2024-06-03_11-48-34

@lllv-len
Copy link
Author

lllv-len commented Jun 6, 2024

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.52-SNAPSHOT/ 问题已修复,请用2.0.52-SNAPSHOT版本帮忙验证

请问什么时候正式发布 2.0.52

@wenshao
Copy link
Member

wenshao commented Jun 6, 2024

预计在6月30日

@wenshao
Copy link
Member

wenshao commented Jul 14, 2024

@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

2 participants