Skip to main content

REST Assured: De-Serialization of the API Response into a POJO

So Deserialization is the process of fetching the stream of data we send to the rest API service site and converting them back into the java object (POJO). So let us use the same serialization example of the goapi rest API site to deserialize our sent JSON payload.

public class serialDeserialTest {
public void DeserTest() throws {

    RestAssured.baseURI = ""+id;

     firstPojo fp = RestAssured.given().when().get().as(firstPojo.class);
  • So to deserialize we have passed the rest API URL with the data-id endpoint we want.
  • Then we instantiated the firstPojo class where the List<dataPojo> is declared.
  • Because through there the object fp gets called and it will access the toString method of dataPojo class and get the list of payload into POJO object.
  • So using rest assured we called the as(firstPojo.class).

Let's see the output:

firstPojo [meta=null, data=[dataPojo [id=1408, name=trinity,, gender=female, status=active]]]
PASSED: DeserTest

    Default test
    Tests run: 1, Failures: 0, Skips: 0

Default suite
Total tests run: 1, Failures: 0, Skips: 0

So in this way, we can serialize and deserialize the data back and forth and use these to our advantage.

Submitted by arilio666 on September 28, 2021

Ashwin is working with iVagus as a Technical Lead. He has experience in various technologies like Cypress, JavaScript, TypeScript, Rest Assured, Selenium, Cucumber, and Java.


At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.