RuddenberryL / json-path

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

ExpressionEvaluator.java does not support Boolean types #15

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Currently the ExpressionEvaluator does not comparison of boolean type.

Test json
{ "store": {
    "book": [ 
      { "category": "reference",
        "author": "Nigel Rees",
        "title": "Sayings of the Century",
        "price": 8.95
      },
      { "category": "fiction",
        "author": "Herman Melville",
        "title": "Moby Dick",
        "isbn": "0-553-21311-3",
        "price": 8.99,
        "retailer": null, 
        "children": true,
        "number": -2.99
      },
      { "category": "fiction",
        "author": "J. R. R. Tolkien",
        "title": "The Lord of the Rings",
        "isbn": "0-395-19395-8",
        "price": 22.99,
        "number":0,
        "children": false
      }
    ]
  }
}

using the expression "$.store.book[?(@.children==true)].title" should return 
"Moby Dick".

---- crude patch ----
else if(actual instanceof Boolean){
            Boolean a = (Boolean)actual;
            Boolean e = Boolean.valueOf(expected);
            if("==".equals(comparator)){
                return a.equals(e);
            } else if ("!=".equals(comparator) || "<>".equals(comparator)) {
                return !a.equals(e);
            }
        }

Original issue reported on code.google.com by anh...@gmail.com on 30 May 2012 at 8:42

GoogleCodeExporter commented 9 years ago

Original comment by kalle.st...@gmail.com on 31 Aug 2012 at 9:09

GoogleCodeExporter commented 9 years ago
This will be part of the upcoming 0.9 release. Note that a List<String> will be 
returned since it's an Array operation and the path is not definite.

List<String> titles = JsonPath.read(json, 
"$.store.book[?(@.children==true)].title"); 

Original comment by kalle.st...@gmail.com on 20 Aug 2013 at 6:45