How to transform the response to the Java list in Rest Assured?

Rest AssuredDynamic ProgrammingProgramming

We can transform the response to Java list in Rest Assured. This can be achieved when we have a JSON array Response. To convert the JSON array to List, we need to use the method as.(List.class).

Once the JSON array Response is converted to a List, we need to convert it to a Map and get all values in the Response in a key-value pair. We shall first send a GET request via Postman on a mock API URL and go through the JSON Response array.


Code Implementation

import java.util.List;
import org.testng.annotations.Test;
import io.restassured.RestAssured;
public class NewTest {
   public void convertResponsetoList() {

      //base URL
      RestAssured.baseURI = "";

      //convert JSON Response array to List
      List<Object> l = RestAssured

      //GET request on Mock URL

      //size of List
      int s = l.size();
      System.out.println("List size is: " + s);


Updated on 22-Nov-2021 10:23:18