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

Profile picture for user arilio666

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.