We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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.eval 对 string和object结果不一致,感觉是个问题
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONPath; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; public class Issue1965_757 { @Test public void testMutant1() { JSONObject obj = JSONObject.of("data", JSONArray.of(1)); String str = JSON.toJSONString(obj); System.out.println(str); System.out.println(JSONPath.eval(obj, "$.data[0][0]")); System.out.println(JSONPath.eval(str, "$.data[0][0]")); assertEquals(JSONPath.eval(str, "$.data[0][0]"), JSONPath.eval(obj, "$.data[0][0]")); } @Test public void testMutant2() { JSONObject obj = JSONObject.of("data", JSONArray.of(1, 2)); String str = JSON.toJSONString(obj); System.out.println(str); System.out.println(JSONPath.eval(obj, "$.data[0][0]")); System.out.println(JSONPath.eval(str, "$.data[0][0]")); assertEquals(JSONPath.eval(str, "$.data[0][0]"), JSONPath.eval(obj, "$.data[0][0]")); } @Test public void testMutant3() { JSONObject obj = JSONObject.of("data", JSONArray.of(JSONObject.of("id", "1"))); String str = JSON.toJSONString(obj); System.out.println(str); System.out.println(JSONPath.eval(obj, "$.data[0][0]")); System.out.println(JSONPath.eval(str, "$.data[0][0]")); assertEquals(JSONPath.eval(str, "$.data[0][0]"), JSONPath.eval(obj, "$.data[0][0]")); } }
// 1 {"data":[1]} 1 null
org.opentest4j.AssertionFailedError: Expected :null Actual :1
// 2 {"data":[1,2]} 1 null
// 3 {"data":[{"id":"1"}]} 1 1
The text was updated successfully, but these errors were encountered:
fix JSONPath#extract, for issue #2584 #2585
5893fc8
https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.51-SNAPSHOT/ 问题已修复,请帮忙用2.0.51-SNAPSHOT版本验证
Sorry, something went wrong.
验证已修复,辛苦温少
https://github.com/alibaba/fastjson2/releases/tag/2.0.51 问题已修复,请用新版本
No branches or pull requests
问题描述
JSONPath.eval 对 string和object结果不一致,感觉是个问题
环境信息
重现步骤
相关日志输出
// 1
{"data":[1]}
1
null
org.opentest4j.AssertionFailedError:
Expected :null
Actual :1
// 2
{"data":[1,2]}
1
null
org.opentest4j.AssertionFailedError:
Expected :null
Actual :1
// 3
{"data":[{"id":"1"}]}
1
1
The text was updated successfully, but these errors were encountered: