Parse JSON to POJO using Java

JSON response:


Parsing the JSON to POJO:

private List<RESTResponseModel> restResponseArray = new ArrayList<RESTResponseModel>();
JSONArray jsonResponse = new JSONArray(getJsonResponse());
for (int k = 0; k<jsonResponse.length();k++){
    RESTResponseModel dm = new RESTResponseModel();
 	JSONObject restRequest=jsonResponse.getJSONObject(k);

	JSONObject restBody = restRequest.optJSONObject("restRequest");
	if (new Long(restBody.optLong("creationDate"))!=null){
		Date date = new Date(restBody.optLong("creationDate"));
		dm.setCreationDate(new SimpleDateFormat("MM/dd/yyyy").format(date));

RESTResponseModel POJO

public class RESTResponseModel {
	private String id;
	private String sessionId;
	private String creationDate;
	private String knowledgeBaseName;
	private String finalOutcomeStatus;	
	public String getId() {
		return id;
	public void setId(String id) { = id;
	public String getSessionId() {
		return sessionId;
	public void setSessionId(String sessionId) {
		this.sessionId = sessionId;
	public String getCreationDate() {
		return creationDate;
	public void setCreationDate(String creationDate) {
		this.creationDate = creationDate;
	public String getKnowledgeBaseName() {
		return knowledgeBaseName;
	public void setKnowledgeBaseName(String knowledgeBaseName) {
		this.knowledgeBaseName = knowledgeBaseName;
	public String getFinalOutcomeStatus() {
		return finalOutcomeStatus;
	public void setFinalOutcomeStatus(String finalOutcomeStatus) {
		this.finalOutcomeStatus = finalOutcomeStatus;


  1. Tilly says:

    Admin do you want unlimited content for your site? Serarch in google:
    Stottai’s Rewriter

  2. Jesse says:

    So finalOutcomeStatus do not have to be in it’s own pojo?

Leave a Comment

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s