Make Selenium Easy

REST Assured Tutorial 61 – Deserialize Using JsonPath

Introduction

As a part of the End to End REST Assured Tutorial, in this post, we will learn to deserialize using JsonPath.

Earlier we have seen De-Serialization – JSON Object To Java Object Using Jackson API. The same we can achieve using JsonPath as well.

Prerequisite

As we are using RestAssured which includes JsonPath dependency by default, there is no need to include JsonPath dependency explicitly. I have used the below version of Rest Assured for this post:-

Deserialization using JsonPath

We will take a very simple JSON Object and will create a POJO for it.

JSON Object Example

Employee POJO

Converting a Java object to a JSON object is called serialization and the reverse of it is called deserialization. JsonPath class provides a method named “T getObject(String path, Class objectType)” which helps to get the result of an Object path expression as a java Object.

Deserialization example

Output

JSON Array example

Above I used “” and “$” as JSON path string as we have a simple JSON Object. If we have a nested or JSON array then we can write a proper JSON path syntax and deserialize only the result of it.

Suppose we have a JSON array as below:-

If we want to deserialize only the second JSON object from the above JSON array, we can do that as well.

Deserialization example for JSON array

Output

You can download/clone the above sample project from here.

You can subscribe to my YouTube channel RetargetCommon to learn from video tutorials.

If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.
#ThanksForReading
#HappyLearning

Find all Selenium related posts here, all API manual and automation related posts here, and find frequently asked Java Programs here.

Many other topics you can navigate through the menu.

Author: Amod Mahajan

My name is Amod Mahajan and I am an IT employee with 6+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went through so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning

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 61 – Deserialize Using JsonPath

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