Third way is similar to first one.Here we get arraylist of ids ,firstNames,lastNames etc by passing “/list” in get method to get the list and by passing id,firstName,lastName etc in path to get all the paths.
Then we loop over the list to print all the values.
Like in first method we used to get a list of responses and from that list we used to fetch the list of first names like this
ArrayList<String> firstNameLists = given().contentType(ContentType.JSON).log().all().get("/list").then().extract().path("firstName");
But this time we will do it differently. We will first fetch the list of reponses
Response resp = given().contentType(ContentType.JSON).log().all().get("/list");
And then get list of ids from it.
List<Integer> allIds = resp.then().extract().path("id");
And then we get lists of other fields like firstName ,lastName etc and then we can loop through all the values using for loop.
List<String> allFirstNames = resp.then().extract().path("firstName");
List<String> allLastNames = resp.then().extract().path("lastName");
List<String> allProgrammes = resp.then().extract().path("programme");
List<String> allEmails = resp.then().extract().path("email");
And then we can use for loop to print these values or use them as per our needs
for(int i =0;i<allIds.size();i++){
System.out.println("The "+i+ " th id is "+allIds.get(i));
System.out.println("The "+i+ " th firstName is "+allFirstNames.get(i));
System.out.println("The "+i+ " th lastName is "+allLastNames.get(i));
System.out.println("The "+i+ " th programme is "+allProgrammes.get(i));
System.out.println("The "+i+ " th email is "+allEmails.get(i));
}