At the end there was example of 'FindAll', but I want to see example of 'Find'.... And how to extract single value.... Map, List, etc...
Thank you,
Charles
Hi Charles,
See both 'find' and 'findAll' have almost similar functionality, both search through the list to match the values passed.
Their syntax is also same. Just that find will extract single value whereas findAll will find all the matching values in the list.
I'll give you a simple example here only, you can implement it by yourself.
Let's say we have this sample JSON:
{
"name" : "abc",
"items" : [
{
"itemName" : "table",
"cost" : 50
},
{
"itemName" : "chair",
"cost" : 75
},
{
"itemName" : "table",
"cost" : 40
}
]
}
Now, on this JSON we'll use both find and findAll
HashMap<Object,Object> item = resp.then().extract().path("items.find{it.itemName == 'table'}");
Output: {"itemName":"table , "cost":50}
Whereas,
ArrayList<HashMap<Object,Object>> item = resp.then().extract().path("items.findAll{it.itemName == 'table'}");
will give output as:
[{"itemName":"table , "cost":50}, {"itemName":"table , "cost":40}]
Thank you! :)
No problem! :)