Library throws ClassCastException in AbstractJsonProvider.toList()
Closed this issue · 2 comments
GoogleCodeExporter commented
What steps will reproduce the problem?
1. JsonPath: $.project[?(@.template.@key == 'foo')].field[*].@key
2. Json Object: (lengthy, see attachment)
3. List<String> fields = JsonPath.read(jsonData, jsonPath);
What is the expected output? What do you see instead?
Should return a List<String> which contains all the "@key" field values of the
"field" substructure ("Artist", ...) , but throws ClassCastException instead.
What version of the product are you using? On what operating system?
V. 0.8.0 on Win7 64 bit / Java 6 / Tomcat 6.
Please provide any additional information below.
java.lang.ClassCastException: net.minidev.json.JSONObject cannot be cast to
java.util.List
at com.jayway.jsonpath.spi.impl.AbstractJsonProvider.toList(AbstractJsonProvider.java:55)
at com.jayway.jsonpath.internal.filter.ArrayEvalFilter.filter(ArrayEvalFilter.java:40)
at com.jayway.jsonpath.internal.filter.PathTokenFilter.filter(PathTokenFilter.java:50)
at com.jayway.jsonpath.JsonPath.read(JsonPath.java:182)
at com.jayway.jsonpath.JsonPath.read(JsonPath.java:202)
at com.jayway.jsonpath.JsonPath.read(JsonPath.java:307)
Original issue reported on code.google.com by matthias...@zeutschel.de
on 9 Jan 2013 at 7:36
Attachments:
GoogleCodeExporter commented
[deleted comment]
GoogleCodeExporter commented
Not very helpful stack trace. This is fixed in version 0.9, soon to be
released.
New stack trace:
com.jayway.jsonpath.InvalidPathException: The path fragment '[?(@.template.@key
=='foo')]' can not be applied to a JSON object only a JSON array.
at com.jayway.jsonpath.internal.filter.ArrayEvalFilter.filter(ArrayEvalFilter.java:56)
...
The main issue with your path is that you try to filter a JSON object
$.projects (a Map) with a Array filter.
Is there a typo in your sample json? If not try $.project.field[*].@key
Original comment by kalle.st...@gmail.com
on 20 Aug 2013 at 10:56
- Changed state: Fixed