From db59d0ba216bc246657e52930ad8ecb5c67eda4b Mon Sep 17 00:00:00 2001 From: Jochen Berger Date: Fri, 17 Mar 2017 09:35:02 +0100 Subject: [PATCH] use json-smart to parse the query --- .../com/jayway/jsonpath/internal/filter/ValueNode.java | 10 +++++++++- .../src/test/java/com/jayway/jsonpath/JacksonTest.java | 10 ++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/filter/ValueNode.java b/json-path/src/main/java/com/jayway/jsonpath/internal/filter/ValueNode.java index 7506358a..2eb45939 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/filter/ValueNode.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/filter/ValueNode.java @@ -11,6 +11,10 @@ import com.jayway.jsonpath.internal.Utils; import com.jayway.jsonpath.internal.path.PathCompiler; import com.jayway.jsonpath.internal.path.PredicateContextImpl; import com.jayway.jsonpath.spi.json.JsonProvider; + +import net.minidev.json.parser.JSONParser; +import net.minidev.json.parser.ParseException; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -343,7 +347,11 @@ public abstract class ValueNode { } public Object parse(Predicate.PredicateContext ctx){ - return parsed ? json : ctx.configuration().jsonProvider().parse(json.toString()); + try { + return parsed ? json : new JSONParser(JSONParser.MODE_PERMISSIVE).parse(json.toString()); + } catch (ParseException e) { + throw new IllegalArgumentException(e); + } } public boolean isParsed() { diff --git a/json-path/src/test/java/com/jayway/jsonpath/JacksonTest.java b/json-path/src/test/java/com/jayway/jsonpath/JacksonTest.java index 7799c9d7..ef79e22a 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/JacksonTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/JacksonTest.java @@ -45,4 +45,14 @@ public class JacksonTest extends BaseTest { assertThat(date).isEqualTo(now); } + @Test + // https://github.com/jayway/JsonPath/issues/275 + public void single_quotes_work_with_in_filter() { + final String jsonArray = "[{\"foo\": \"bar\"}, {\"foo\": \"baz\"}]"; + final Object readFromSingleQuote = JsonPath.using(JACKSON_CONFIGURATION).parse(jsonArray).read("$.[?(@.foo in ['bar'])].foo"); + final Object readFromDoubleQuote = JsonPath.using(JACKSON_CONFIGURATION).parse(jsonArray).read("$.[?(@.foo in [\"bar\"])].foo"); + assertThat(readFromSingleQuote).isEqualTo(readFromDoubleQuote); + + } + }