Reputation: 4637
I am using restassured framework, and inside it, it has JsonPath class. JsonPath has a method signature of getList(String path, Class T);
I have attempt to do something like this:
List<JsonPath> myList = myJsonPathObject.getList("mypath", JsonPath.class);
And I get a runtime casting exception. So what would be the correct format in calling this. I also attempted:
List<JsonPath> myList = myJsonPathObject.getList("mypath", new ArrayList<JsonPath>().getClass());
And that also failed. Actually that failed compilation.
Upvotes: 1
Views: 5785
Reputation: 4637
I know this is an old threat, but someone commented and reminded me of this. I actually found an answer to this question.
What I had to do was cast it into a Map<String, Object>
and while iterating through the objects, I have to cast the object into the appropriate class.
Map<String, Object> myMap = (Map<String, Object>) myJsonPathObject.get("mypath");
for (String key : myMap.getKeySet()) {
Map<String, Object> subMyMap = (Map<String, Object>) myMap.get(key);
}
So now I can continue to get additional mockup, json within a json.
Upvotes: 0
Reputation: 40618
JsonPath is used to extract values out of a JSON document. You cannot get a list of "JsonPath" out of JSON document.
Upvotes: 2