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

JSONPath.remove 与fastjson1.x行为不一致 #1889

Closed
Vinke2 opened this issue Sep 22, 2023 · 9 comments
Closed

JSONPath.remove 与fastjson1.x行为不一致 #1889

Vinke2 opened this issue Sep 22, 2023 · 9 comments
Labels
bug Something isn't working fixed
Milestone

Comments

@Vinke2
Copy link

Vinke2 commented Sep 22, 2023

fastjson1.x:移除了key和value
fastjson2.0.40:仅移除了value

@Vinke2 Vinke2 added the bug Something isn't working label Sep 22, 2023
@Vinke2
Copy link
Author

Vinke2 commented Sep 26, 2023

另:使用兼容包 JSON.parseObject后内部的JSONobject为fastjson2.x的对象

@wenshao
Copy link
Member

wenshao commented Sep 26, 2023

能提供重现问题的testcase么?

@Vinke2
Copy link
Author

Vinke2 commented Sep 27, 2023

    String text = "{\n" +
            "  \"a\": {\n" +
            "    \"b\": 0,\n" +
            "    \"c\": 2\n" +
            "  }\n" +
            "}";
    JSONObject jsonObject = JSON.parseObject(text);
    JSONPath.remove(jsonObject, "$..b");
    System.out.println(JSON.toJSONString(jsonObject, JSONWriter.Feature.WriteNulls));

这个是fastjson2 结果:{"a":{"b":null,"c":2}}

@Vinke2
Copy link
Author

Vinke2 commented Sep 27, 2023

    String text = "{\n" +
            "  \"a\": {\n" +
            "    \"b\": 0,\n" +
            "    \"c\": 2\n" +
            "  }\n" +
            "}";
    JSONObject jsonObject = JSON.parseObject(text);
    JSONPath.remove(jsonObject, "$..b");
    System.out.println(JSON.toJSONString(jsonObject, SerializerFeature.WriteMapNullValue));

这是fastjson1 结果:{"a":{"c":2}}

@Vinke2
Copy link
Author

Vinke2 commented Sep 27, 2023

    JSONObject jsonObject = new JSONObject();
    JSONPath.set(jsonObject,"$a.d", new JSONObject().fluentPut("cc",1));
    System.out.println(jsonObject.get("a").getClass().getName());
    System.out.println(jsonObject.getJSONObject("a").get("d").getClass().getName());

image

是使用JSONPath.set后发现的,不是parseObject,前面描述有误

@wenshao wenshao added this to the 2.0.41 milestone Oct 5, 2023
wenshao added a commit that referenced this issue Oct 5, 2023
@wenshao wenshao added the fixed label Oct 5, 2023
@wenshao
Copy link
Member

wenshao commented Oct 6, 2023

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

@wenshao wenshao closed this as completed Oct 6, 2023
@Vinke2
Copy link
Author

Vinke2 commented Oct 8, 2023

    JSONObject jsonObject = new JSONObject();
    JSONPath.set(jsonObject,"$a.d", new JSONObject().fluentPut("cc",1));
    System.out.println(jsonObject.get("a").getClass().getName());
    System.out.println(jsonObject.getJSONObject("a").get("d").getClass().getName());

image

是使用JSONPath.set后发现的,不是parseObject,前面描述有误

这个问题还未修复吧

@wenshao
Copy link
Member

wenshao commented Oct 8, 2023

是两个事情了,你能再建一个issue么?

@Vinke2
Copy link
Author

Vinke2 commented Oct 8, 2023

是两个事情了,你能再建一个issue么?

行,我再建一个issue

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