spark85 / json-path

Automatically exported from code.google.com/p/json-path
0 stars 0 forks source link

JsonPath folds list of lists of something to list of something #36

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Json Document Example:
{ "arrayOfObjectsAndArrays" : [ { "k" : ["json"] }, { "k":["path"] }, { "k" : 
["is"] }, { "k" : ["cool"] } ],
  "arrayOfObjects" : [{"k" : "json"}, {"k":"path"}, {"k" : "is"}, {"k" : "cool"}]
}

What steps will reproduce the problem?
1. Given the Json Document Example (above)
2. Given at least the v 0.8.1 of the json-path jayway implementation
3. When you use any of these json-paths: $.arrayOfObjects..k and $. 
arrayOfObjectsAndArrays..k
4. Then the result is this for both json-paths listed above:  
["json","path","is","cool"]

What is the expected output? What do you see instead?
The expected output is:  ["json","path","is","cool"] and 
[["json"],["path"],["is"],["cool"]] respectively.

What version of the product are you using? On what operating system?
The version is 0.8.1

Please provide any additional information below.

In 0.8.1 the cause of this issue is an addAll during traversal when an element 
is a list.  This addAll ends up adding the contents of the list rather than the 
list themselves into the final result.

Original issue reported on code.google.com by michelbe...@gmail.com on 18 Sep 2013 at 3:19

GoogleCodeExporter commented 9 years ago
Fixed and will be part of 0.9.0 release. 

    @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());
    }

Original comment by kalle.st...@gmail.com on 18 Sep 2013 at 5:40