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]多层嵌套json,包含多个arr时,使用JSONPath无法获取到期望值 #487

Closed
qsj opened this issue Jun 18, 2022 · 2 comments
Labels
bug Something isn't working jsonpath
Milestone

Comments

@qsj
Copy link

qsj commented Jun 18, 2022

问题描述

目标JSON是一个多层嵌套的json,如:{"v1":[{"v2":[{"v3":{"v4":1}}]}]} 使用jsonpath:$.v1[].v2[].v3.v4 期望得到[1],但是得到了null

环境信息

请填写以下信息:

  • OS信息: windows 10
  • JDK信息: jdk 1.8.0_281
  • 版本信息:Fastjson2 2.0.7

重现步骤

如何操作可以重现该问题:

@Test
public void testNestedJson(){
    Assert.assertEquals("[1]",
                        JSON.toJSONString(
                            JSONPath.of("$.v1[*].v2[*].v3.v4")
                            .extract(
                                JSONReader.of("{\"v1\":[{\"v2\":[{\"v3\":{\"v4\":1}}]}]}")
                            )
                        )
                       );
}

期待的正确结果

对您期望发生的结果进行清晰简洁的描述。

执行通过

相关日志输出

请复制并粘贴任何相关的日志输出。

org.junit.ComparisonFailure: 
Expected :[1]
Actual   :null
<Click to see difference>


	at org.junit.Assert.assertEquals(Assert.java:117)
	at org.junit.Assert.assertEquals(Assert.java:146)
	at com.secsmart.JsonParseTest.testNestedJson(JsonParseTest.java:112)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)

附加信息

如果你还有其他需要提供的信息,可以在这里填写(可以提供截图、视频等)。

@qsj qsj added the bug Something isn't working label Jun 18, 2022
@wenshao wenshao added this to the 2.0.8 milestone Jun 18, 2022
@wenshao
Copy link
Member

wenshao commented Jun 18, 2022

@wenshao
Copy link
Member

wenshao commented Jun 25, 2022

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

@wenshao wenshao closed this as completed Jun 25, 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 jsonpath
Projects
None yet
Development

No branches or pull requests

2 participants