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.extract 与 eval 表现不一致 #553

Closed
wkclz opened this issue Jul 12, 2022 · 2 comments
Closed

[BUG] JSONPath.extract 与 eval 表现不一致 #553

wkclz opened this issue Jul 12, 2022 · 2 comments
Labels
bug Something isn't working
Milestone

Comments

@wkclz
Copy link

wkclz commented Jul 12, 2022

问题描述

在 fastjson2 中,JSONPath.extract 与 eval 表现不一致
在 fastjson 1.2.83 中是正常的。

环境信息

  • OS信息: CentOS7.9
  • JDK信息:OracleJDK17
  • 版本信息:Fastjson2: 2.0.9

重现步骤

    public static void main(String[] args) {
        String json = "{\"status\":0}";
        String path = "$.status";
        Object rt1 = JSONPath.extract(json, path);
        System.out.println(rt1);// 0
        Object rt2 = JSONPath.eval(json, path);
        System.out.println(rt2);// null
    }

期待的正确结果

需要表现一致

@wkclz wkclz added the bug Something isn't working label Jul 12, 2022
@wenshao wenshao added this to the 2.0.10 milestone Jul 13, 2022
@wkclz
Copy link
Author

wkclz commented Jul 15, 2022

这,,是因为入参是String 的问题嘛,试了当 入参数是 String, path 是多级(非json的1级)时,是正常的。

以下例子,eval 的第一个参数仍然是字符串,但在 fastjson 1.2.83, fastjson2.0.9 都是正常的。只有 path 取一级的时候才会是空

    public static void main(String[] args) {
        String json = "{\"status\":0,\"data\":{\"code\":0}}";
        String path = "$.data.code";
        Object rt1 = JSONPath.extract(json, path);
        System.out.println(rt1);// 0
        Object rt2 = JSONPath.eval(json, path);
        System.out.println(rt2);// null
    }

@wenshao
Copy link
Member

wenshao commented Jul 23, 2022

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

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

No branches or pull requests

2 participants