Browse Source

Merge pull request #331 from jochenberger/fix-json-org-provider

fix result if object does not contain key (fixes #270)
pull/332/head
kallestenflo 8 years ago committed by GitHub
parent
commit
a766f13561
  1. 4
      json-path/src/main/java/com/jayway/jsonpath/spi/json/JsonOrgJsonProvider.java
  2. 8
      json-path/src/test/java/com/jayway/jsonpath/JsonOrgJsonProviderTest.java

4
json-path/src/main/java/com/jayway/jsonpath/spi/json/JsonOrgJsonProvider.java

@ -96,8 +96,8 @@ public class JsonOrgJsonProvider extends AbstractJsonProvider {
public Object getMapValue(Object obj, String key) {
try {
JSONObject jsonObject = toJsonObject(obj);
Object o = jsonObject.get(key);
if (!jsonObject.has(key)) {
Object o = jsonObject.opt(key);
if (o == null) {
return UNDEFINED;
} else {
return unwrap(o);

8
json-path/src/test/java/com/jayway/jsonpath/JsonOrgJsonProviderTest.java

@ -44,4 +44,12 @@ public class JsonOrgJsonProviderTest extends BaseTest {
assertThat(books.size()).isEqualTo(4);
}
@Test
public void read_books_with_isbn() {
JSONArray books = using(JSON_ORG_CONFIGURATION).parse(JSON_DOCUMENT).read("$..book[?(@.isbn)]");
assertThat(books.length()).isEqualTo(2);
}
}

Loading…
Cancel
Save