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

[?(@ empty false)] Filter is not working after json-path 2.4.0 release #900

Open
rosensilva opened this issue Mar 10, 2023 · 3 comments
Open

Comments

@rosensilva
Copy link

Hello,

We noticed that the ?(@ empty false) expression is not working with the latest json-path version. I have tried this with a simple java program with versions 2.4.0 to 2.7.0. Seems like this is broken from 2.5.0 upwards.

Below is the sample java program,

package org.example;

import com.jayway.jsonpath.JsonPath;

public class Main {
    public static void main(String[] args) {
        String scenarioStateJson ="{\n" +
                "  \"data1\": {\n" +
                "    \"data\": [\n" +
                "      {\n" +
                "        \"attribute1\": \"string1\",\n" +
                "        \"attribute2\": \"string2\"\n" +
                "      },\n" +
                "      {\n" +
                "        \"attribute1\": \"string3\",\n" +
                "        \"attribute2\": \"string4\"\n" +
                "      }\n" +
                "    ]\n" +
                "  },\n" +
                "  \"data2\": {\n" +
                "    \"data\": [\n" +
                "      {}\n" +
                "    ]\n" +
                "  },\n" +
                "  \"data3\": {\n" +
                "    \"data\": [\n" +
                "      {\n" +
                "        \"attribute1\": \"string5\",\n" +
                "        \"attribute2\": \"string6\"\n" +
                "      },\n" +
                "      {\n" +
                "        \"attribute1\": \"string7\",\n" +
                "        \"attribute2\": \"string8\"\n" +
                "      }\n" +
                "    ]\n" +
                "  }\n" +
                "}";
        JsonPath jsonPath = JsonPath.compile("$..data.*[?(@ empty false)]");
        Object jsonPathValue = jsonPath.read(scenarioStateJson);
    }
}

The following exception is thrown,

Exception in thread "main" java.lang.ClassCastException: class java.util.LinkedHashMap cannot be cast to class java.util.Collection (java.util.LinkedHashMap and java.util.Collection are in module java.base of loader 'bootstrap')
	at com.jayway.jsonpath.internal.filter.ValueNodes$JsonNode.isEmpty(ValueNodes.java:177)
	at com.jayway.jsonpath.internal.filter.EvaluatorFactory$EmptyEvaluator.evaluate(EvaluatorFactory.java:167)
	at com.jayway.jsonpath.internal.filter.RelationalExpressionNode.apply(RelationalExpressionNode.java:44)
	at com.jayway.jsonpath.internal.filter.FilterCompiler$CompiledFilter.apply(FilterCompiler.java:415)
	at com.jayway.jsonpath.internal.path.PredicatePathToken.accept(PredicatePathToken.java:77)
	at com.jayway.jsonpath.internal.path.PredicatePathToken.evaluate(PredicatePathToken.java:47)
	at com.jayway.jsonpath.internal.path.PathToken.handleArrayIndex(PathToken.java:134)
	at com.jayway.jsonpath.internal.path.WildcardPathToken.evaluate(WildcardPathToken.java:42)
	at com.jayway.jsonpath.internal.path.PathToken.handleObjectProperty(PathToken.java:81)
	at com.jayway.jsonpath.internal.path.PropertyPathToken.evaluate(PropertyPathToken.java:79)
	at com.jayway.jsonpath.internal.path.ScanPathToken.walkObject(ScanPathToken.java:76)
	at com.jayway.jsonpath.internal.path.ScanPathToken.walk(ScanPathToken.java:41)
	at com.jayway.jsonpath.internal.path.ScanPathToken.walkObject(ScanPathToken.java:84)
	at com.jayway.jsonpath.internal.path.ScanPathToken.walk(ScanPathToken.java:41)
	at com.jayway.jsonpath.internal.path.ScanPathToken.evaluate(ScanPathToken.java:36)
	at com.jayway.jsonpath.internal.path.RootPathToken.evaluate(RootPathToken.java:62)
	at com.jayway.jsonpath.internal.path.CompiledPath.evaluate(CompiledPath.java:99)
	at com.jayway.jsonpath.internal.path.CompiledPath.evaluate(CompiledPath.java:107)
	at com.jayway.jsonpath.JsonPath.read(JsonPath.java:183)
	at com.jayway.jsonpath.JsonPath.read(JsonPath.java:341)
	at com.jayway.jsonpath.JsonPath.read(JsonPath.java:325)
	at org.example.Main.main(Main.java:42)
@chandimajayawickrama
Copy link

Hi,

A kind reminder on this.

Thanks & Regards,
Chandima

rosensilva added a commit to rosensilva/JsonPath that referenced this issue Apr 14, 2023
@piotrlg9
Copy link

@dulanjalidilmi
Copy link

Hi Team,

Any update on this issue?

Best Regards
Dilmi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants