alibaba / fastjson2

🚄 FASTJSON2 is a Java JSON library with excellent performance.
Apache License 2.0
3.77k stars 493 forks source link

JSONPath eval throw Exception #118

Open wsxe9988 opened 2 years ago

wsxe9988 commented 2 years ago

//1.加载json

        String text = ("{code:1,msg:'Hello world',data:{list:[1,2,3,4,5], ary2:[{a:2},{a:3,b:{c:'ddd'}}]}}");
        JSONObject obj = JSON.parseObject(text);

        JSONPath.extract(text,"$.data.list[?(@ in $..ary2[0].a)]");

        long start = System.currentTimeMillis();
        for(int i=0,len=1000000; i<len; i++) {
            JSONPath.eval(obj,"$.data.list[?(@ in $..ary2[0].a)]");
        }

        long times = System.currentTimeMillis() - start;

        System.out.println(times);

com.alibaba.fastjson2.JSONException: syntax error, $

at com.alibaba.fastjson2.JSONPath.parseFilter(JSONPath.java:637)
at com.alibaba.fastjson2.JSONPath.of(JSONPath.java:530)
at com.alibaba.fastjson2.JSONPath.extract(JSONPath.java:48)
at com.alibaba.fastjson_perf.JSONPathTest2.test42(JSONPathTest2.java:128)
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:497)
at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:725)
at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)

在 最新的snapshot版本

wenshao commented 2 years ago

2.0.2版本不会支持这种jsonpath表达式,这个后续会支持,但不是2.0.2版本