0
{
 "success": true,
 "data": {
 "count": 0,
 "list": []
 }
}

I have a json data where I want to check count and print it's value

First of all I am using jsonpath() function because it's rest-assured and putting response inside it

ArrayList a = response.jsonPath().get("data");

Above code is giving an error :

java.lang.ClassCastException: java.util.HashMap cannot be cast to java.util.ArrayList

Brhaka
  • 1,622
  • 3
  • 11
  • 31
Parth Makwana
  • 51
  • 1
  • 9

2 Answers2

2

The simplest solution would be to use JsonPath like this:

int count = response.jsonPath().getInt("data.count");
Fenio
  • 3,528
  • 1
  • 13
  • 27
0

Your data property contains a json object not a json-array. Therefore, you cannot cast it to an ArrayList. It should be,

Map<String, Object> data = (Map<String, Object>)response.jsonPath().get("data");
int count = ((Number) data.get("count")).intValue();
Nigel
  • 95
  • 1
  • 10