diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/filter/FieldFilter.java b/json-path/src/main/java/com/jayway/jsonpath/internal/filter/FieldFilter.java index 63270041..9c013552 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/filter/FieldFilter.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/filter/FieldFilter.java @@ -54,9 +54,12 @@ public class FieldFilter extends PathTokenFilter { if(split.length == 1){ if (keys.contains(condition)) { Object o = jsonProvider.getProperty(current, condition); - if (jsonProvider.isArray(o)) { + + boolean isArr = jsonProvider.isArray(o); + boolean isEnd = pathToken.isEndToken(); + if (isArr && !isEnd) { for(Object item : jsonProvider.toIterable(o)){ - jsonProvider.setProperty(result, jsonProvider.length(result), item); + jsonProvider.setProperty(result, jsonProvider.length(result), item); } } else { jsonProvider.setProperty(result, jsonProvider.length(result), jsonProvider.getProperty(current, condition)); diff --git a/json-path/src/test/java/com/jayway/jsonpath/HttpProviderTest.java b/json-path/src/test/java/com/jayway/jsonpath/HttpProviderTest.java index 5e238637..cd1d5417 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/HttpProviderTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/HttpProviderTest.java @@ -2,6 +2,7 @@ package com.jayway.jsonpath; import com.jayway.jsonpath.internal.IOUtils; import com.jayway.jsonpath.spi.HttpProviderFactory; +import org.junit.Ignore; import org.junit.Test; import java.io.IOException; @@ -16,6 +17,7 @@ import static junit.framework.Assert.assertEquals; * Date: 3/10/12 * Time: 8:12 AM */ +@Ignore public class HttpProviderTest { diff --git a/json-path/src/test/java/com/jayway/jsonpath/IssuesTest.java b/json-path/src/test/java/com/jayway/jsonpath/IssuesTest.java index 7d4d73d1..b77e15c1 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/IssuesTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/IssuesTest.java @@ -25,6 +25,27 @@ import static org.junit.Assert.assertThat; */ public class IssuesTest { + + @Test + public void issue_36() { + + String json = "{\n" + + "\n" + + " \"arrayOfObjectsAndArrays\" : [ { \"k\" : [\"json\"] }, { \"k\":[\"path\"] }, { \"k\" : [\"is\"] }, { \"k\" : [\"cool\"] } ],\n" + + "\n" + + " \"arrayOfObjects\" : [{\"k\" : \"json\"}, {\"k\":\"path\"}, {\"k\" : \"is\"}, {\"k\" : \"cool\"}]\n" + + "\n" + + " }"; + + Object o1 = JsonPath.read(json, "$.arrayOfObjectsAndArrays..k "); + Object o2 = JsonPath.read(json, "$.arrayOfObjects..k "); + + assertEquals("[[\"json\"],[\"path\"],[\"is\"],[\"cool\"]]", o1.toString()); + assertEquals("[\"json\",\"path\",\"is\",\"cool\"]", o2.toString()); + + + } + @Test(expected = PathNotFoundException.class) public void issue_11() throws Exception { String json = "{ \"foo\" : [] }"; diff --git a/json-path/src/test/java/com/jayway/jsonpath/JsonPathTest.java b/json-path/src/test/java/com/jayway/jsonpath/JsonPathTest.java index 3ade8992..ee2ae0f9 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/JsonPathTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/JsonPathTest.java @@ -276,7 +276,7 @@ public class JsonPathTest { //List books = JsonPath.>read(DOCUMENT, "$..book"); Object books = JsonPath.>read(DOCUMENT, "$..book"); - System.out.println("test"); + System.out.println(books); }