I'm writing a smoke test using rest-assured and want to traverse the api to make sure no unexpected errors occur.
I have a data structure that looks like this:
{
...
"sites": [
{
...
"groups": [
{
...
"locations": [
{
...
"racks": [
{
"rackId": 123456789,
...
},
{
"rackId": 987654321,
...
},
...
]
}
]
}
]
},
{
...
"groups": [
{
...
"locations": [
{
...
"racks": [
{
"rackId": 11111111,
...
},
{
"rackId": 22222222,
...
},
...
]
}
]
}
]
},
...
]
}
Using JsonPath bundled in RestAssured I'm trying to get a flat list of all rackIds to then call subsequent requests for these rackIds.
jsonPath.getList("sites.groups.locations.racks.rackId", Long.class);
>> java.lang.NumberFormatException: For input string: "[[[406071537, 406071538, 406071539, 406071540, 406071541]]]"
I tried using this path, but didn't work because I believe this syntax only works with the other JsonPath implementation, not the one bundled with rest-assured
"$.sites[*].groups[*].locations[*].racks[*].rackId"
I now came down to this, that gives me lists of lists of lists, that I could then flatten myself. But I then have the issue, that the numbers interpreted as Integers by default, but I'm receiving Long values.
List list = jsonPath.getList("sites.groups.locations.racks.rackId");
Any ideas?
Just use flatten()
:
List list = jsonPath.getList("sites.groups.locations.racks.rackId.flatten()");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With