Browse Source

use json-smart to parse the query

pull/314/head
Jochen Berger 8 years ago
parent
commit
db59d0ba21
  1. 10
      json-path/src/main/java/com/jayway/jsonpath/internal/filter/ValueNode.java
  2. 10
      json-path/src/test/java/com/jayway/jsonpath/JacksonTest.java

10
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.PathCompiler;
import com.jayway.jsonpath.internal.path.PredicateContextImpl; import com.jayway.jsonpath.internal.path.PredicateContextImpl;
import com.jayway.jsonpath.spi.json.JsonProvider; 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.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -343,7 +347,11 @@ public abstract class ValueNode {
} }
public Object parse(Predicate.PredicateContext ctx){ 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() { public boolean isParsed() {

10
json-path/src/test/java/com/jayway/jsonpath/JacksonTest.java

@ -45,4 +45,14 @@ public class JacksonTest extends BaseTest {
assertThat(date).isEqualTo(now); 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);
}
} }

Loading…
Cancel
Save