Make Selenium Easy

REST Assured Tutorial 75 – What Is Serialization And Deserialization In Rest Assured?


As a part of RestAssured Tutorials End To End, we will learn about the Serialization and Deserialization in Rest Assured in this post.

In fact, Serialization and Deserialization are not specific to RestAssured. It is related to programming language i.e. Java here.

What is Serialization and Deserialization?

Serialization is a conversion of the state of a Java object to a byte stream and Deserialization is the reverse of it i.e. conversion of a byte stream to corresponding Java object. A serialized object can be stored in files, external sources, databases etc and can also be transferred over networks.

To make a Java object serializable, either its class or any of its superclasses implements either the Serializable interface or its subinterface Externalizable. A class that implements Serializable or Externalizable are actually Java Beans.

A Plain Old Java Object i.e. POJO has no such restriction. We generally use POJOs to create JSON payload and convert JSON response payload to Java objects. Converting a POJO object to a JSON object is Serialization and converting a JSON object to a POJO object is called deserialization. These conversions can be done with help of Java libraries like Jackson, Gson etc. We don’t need to implement the required interfaces for POJO classes.

We will use Jackson Databind in this post. You can either download Jackson jar or use its dependency in your Maven/Gradle project. I am using below latest dependency of Jackson Databind for this post –

Conversion of POJO Object to JSON Object in Rest Assured Using Jackson

I will create a very simple POJO as below:-

To convert any object of the above Pojo class to a JSON object, we need to perform the below steps:-

  1. Create an object of POJO class.
  2. Set values of properties of Pojo class
  3. Create an object of ObjectMapper class provided by Jackson.
  4. Use overloaded writeXXXXXX() method as per need. I will convert POJO object to JSON string.


Conversion of JSON Object to POJO Object in Rest Assured Using Jackson

To convert a JSON object to a POJO object we can use ObjectMapper again with its overloaded readXXXX() methods. Please note we can also convert a JSON object to any other type i.e. Map and List instead of POJO.


If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe to my YouTube channel.

Author: Amod Mahajan

A software Tester who is paid to judge products developed by others. Currently getting paid in American Dollars. Writing technical posts and creating YouTube videos are my hobbies.

2 thoughts on “REST Assured Tutorial 75 – What Is Serialization And Deserialization In Rest Assured?

Leave a Reply

Please wait...

Subscribe to new posts to become automation expert

Want to be notified when my new post is published? Get my posts in your inbox.

REST Assured Tutorial 75 – What Is Serialization And Deserialization In Rest Assured?

by Amod Mahajan time to read: 3 min
%d bloggers like this: