fastjson JSONPath Multi Predicates Sytax Combination Support Error

7y4bm7vi  于 2021-11-27  发布在  Java
关注(0)|答案(0)|浏览(237)
  1. support

# obj exist operation

$.zoos[?(@.cats) && ?(@.dogs)]

# string operation

$.zoos[?(@.cats=='30' && @.dogs='20')]

1.NOTsupport


# obj exist operation

$.zoos[?(@.cats && @.dogs)]

# string operation

$.zoos[?(@.cats=='30') && ?(@.dogs='20')]

There is the test code:

public class IssueTest {
    private static final String rawJsonStr = "{\"zoos\":[{\"cats\":[{\"name\":\"cat0\",\"favorite\":\"kiki\"},{\"name\":\"cat1\",\"favorite\":\"chuchu\"}],\"dogs\":[{\"name\":\"dog0\",\"favorite\":\"kiki\"},{\"name\":\"dog1\",\"favorite\":\"chuchu\"}]},{\"cats\":[{\"name\":\"cat3\",\"favorite\":\"gigi\"}],\"dogs\":[]},{\"cats\":[]},{\"cats\":\"not array type\"},{\"cats\":\"30\",\"dogs\":\"20\"},{\"cats\":null}]}";
    @Test
    public void testSideEffectWhenNormal() {
        System.out.println(JSONPath.eval(rawJsonStr, "$.zoos[?(@.cats) && ?(@.dogs)]"));
        // [{"cats":[{"name":"cat0","favorite":"kiki"},{"name":"cat1","favorite":"chuchu"}],"dogs":[{"name":"dog0","favorite":"kiki"},{"name":"dog1","favorite":"chuchu"}]},{"cats":[{"name":"cat3","favorite":"gigi"}],"dogs":[]},{"cats":"30","dogs":"20"}]

        System.out.println(JSONPath.eval(rawJsonStr, "$.zoos[?(@.cats && @.dogs)]"));
        // com.alibaba.fastjson.JSONPathException: illeal jsonpath syntax. $.zoos[?(@.cats && @.dogs)]
    }
}

There is thestackof exception :

com.alibaba.fastjson.JSONPathException: illeal jsonpath syntax. $.zoos[?(@.cats && @.dogs)]

	at com.alibaba.fastjson.JSONPath$JSONPathParser.readName(JSONPath.java:1652)
	at com.alibaba.fastjson.JSONPath$JSONPathParser.readOp(JSONPath.java:1611)
	at com.alibaba.fastjson.JSONPath$JSONPathParser.parseArrayAccessFilter(JSONPath.java:909)
	at com.alibaba.fastjson.JSONPath$JSONPathParser.parseArrayAccess(JSONPath.java:832)
	at com.alibaba.fastjson.JSONPath$JSONPathParser.readSegement(JSONPath.java:805)
	at com.alibaba.fastjson.JSONPath$JSONPathParser.explain(JSONPath.java:1716)
	at com.alibaba.fastjson.JSONPath.init(JSONPath.java:61)
	at com.alibaba.fastjson.JSONPath.eval(JSONPath.java:71)
	at com.alibaba.fastjson.JSONPath.eval(JSONPath.java:499)
	at com.alibaba.fastjson.deserializer.issue2914.Issue2914Test.testSideEffectWhenNormal(Issue2914Test.java:57)
	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:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	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)

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题