Saturday, 24 April 2021

How to Create POJO class? How to convert json to pojo?










Check the below link for question and answers with code:

Top API Interview Question 1-10

 


In the below pojo structure name is a string, jobs are a list of string, and cityModels is a map list. So for cityModels we need to create a separate POJO class as we have done below.

POJO Structure:

{

"name": "morpheus", "jobs": ["tester","developer","support"] "cityModels":[ { "Name":"bangalore", "Temperature":"30" }, { "Name":"delhi", "Temperature":"40" } ] }

POJO CLASS:


package pojo;


import java.util.List;


public class pojoTry {

private String name; // this is for the name filed in pojo

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

private List<String> jobs; // this is for jobs filed in pojo

public List<String> getJobs() {

return jobs;

}

public void setJobs(List<String> jobs) {

this.jobs = jobs;

}

private List<cityModel> citymodels; //refer the city model class below, we have created separate pojo class for it as it is a list of map

public List<cityModel> getCitymodels() {

return citymodels;

}

public void setCitymodels(List<cityModel> citymodels) {

this.citymodels = citymodels;

}


}


CityModel class:

package pojo;


public class cityModel {

private String name;

public String getName() {

return name;

}


public void setName(String name) {

this.name = name;

}


public String getTemperature() {

return temperature;

}


public void setTemperature(String temperature) {

this.temperature = temperature;

}


private String temperature;


}


*************************************************

SeleniumWebdriver Automation Testing Interview Questions:

API Testing Interview Question Set:
https://automationreinvented.blogspot.com/search/label/Rest-API

 
Kubernetes Interview Question Set
https://automationreinvented.blogspot.com/search/label/Kubernetes

 
Docker Interview Question Set
https://automationreinvented.blogspot.com/2020/02/top-18-docker-commands-for-aytomation.html

 
Linux Interview question Set
https://automationreinvented.blogspot.com/search/label/Linux

 
Automation Testing/SDET Framework Design
https://automationreinvented.blogspot.com/search/label/FrameworkDesign


Java Related Interview Question Set

https://automationreinvented.blogspot.com/search/label/Java


GIT Interview Question Set:
https://automationreinvented.blogspot.com/search/label/GIT


Coding Interview Question Set:
https://automationreinvented.blogspot.com/search/label/Coding%20Questions



No comments:

Post a Comment

All Time Popular Posts

Most Featured Post

Introduction to Web Testing with Playwright

  Introduction to Web Testing with Playwright 📌  Telegram Group:  https://t.me/+FTf_NPb--GQ2ODhl 📌  YouTube channel:  https://lnkd.in/gGUG...