![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to transform the response to the Java list in Rest Assured?
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.
Example
Code Implementation
import java.util.List; import org.testng.annotations.Test; import io.restassured.RestAssured; public class NewTest { @Test public void convertResponsetoList() { //base URL RestAssured.baseURI = "https://run.mocky.io/v3"; //convert JSON Response array to List List<Object> l = RestAssured //GET request on Mock URL .get("/1bb42856-4583-4c18-91ed-b9a6ab19efb4") .as(List.class); //size of List int s = l.size(); System.out.println("List size is: " + s); } }
Output
Advertisements