Acid0
Executive Member
Hi all java gurus.
I need some help please.
We are starting to interface with web service from our side and I have started to look into the java side of the web service.
For now luckily just need to consume and at a later stage need to make POST and PUT calls (But that is for a later stage(for now its just GET request I need to worry about))
I have looked into the GSON and retrofit2 side and it seems that both should cater for what I need to do.
I will have a Base url and Uri that takes some parameters and one or two headers to make the call.
So far i have achieved of doing the above and actually get a response back in JSON as below
JSON in second post
As you can see this is just one record and multiple Contact details along with its child records could come through but for now I only focus on one main record and some children records attached.
Following the JSON2POJO
The following classes were created.
Could some one please explain using the above how to actually make the conversion from json to the pojo's in the main class?
Any help would be appreciated
I need some help please.
We are starting to interface with web service from our side and I have started to look into the java side of the web service.
For now luckily just need to consume and at a later stage need to make POST and PUT calls (But that is for a later stage(for now its just GET request I need to worry about))
I have looked into the GSON and retrofit2 side and it seems that both should cater for what I need to do.
I will have a Base url and Uri that takes some parameters and one or two headers to make the call.
So far i have achieved of doing the above and actually get a response back in JSON as below
JSON in second post
As you can see this is just one record and multiple Contact details along with its child records could come through but for now I only focus on one main record and some children records attached.
Following the JSON2POJO
The following classes were created.
Code:
package rest;
import java.util.List;
public class CaptureQuestion {
private Integer captureId;
private Integer questionId;
private Integer questionTypeId;
private String questionTitle;
private List<Object> questionsOptions = null;
private Boolean required;
private String answer;
public Integer getCaptureId() {
return captureId;
}
public void setCaptureId(Integer captureId) {
this.captureId = captureId;
}
public Integer getQuestionId() {
return questionId;
}
public void setQuestionId(Integer questionId) {
this.questionId = questionId;
}
public Integer getQuestionTypeId() {
return questionTypeId;
}
public void setQuestionTypeId(Integer questionTypeId) {
this.questionTypeId = questionTypeId;
}
public String getQuestionTitle() {
return questionTitle;
}
public void setQuestionTitle(String questionTitle) {
this.questionTitle = questionTitle;
}
public List<Object> getQuestionsOptions() {
return questionsOptions;
}
public void setQuestionsOptions(List<Object> questionsOptions) {
this.questionsOptions = questionsOptions;
}
public Boolean getRequired() {
return required;
}
public void setRequired(Boolean required) {
this.required = required;
}
public String getAnswer() {
return answer;
}
public void setAnswer(String answer) {
this.answer = answer;
}
}
-----------------------------------rest.ContactQuestion.java-----------------------------------
package rest;
import java.util.List;
public class ContactQuestion {
private Integer questionId;
private Integer questionTypeId;
private String questionTitle;
private List<QuestionsOption> questionsOptions = null;
private Boolean required;
private String answer;
public Integer getQuestionId() {
return questionId;
}
public void setQuestionId(Integer questionId) {
this.questionId = questionId;
}
public Integer getQuestionTypeId() {
return questionTypeId;
}
public void setQuestionTypeId(Integer questionTypeId) {
this.questionTypeId = questionTypeId;
}
public String getQuestionTitle() {
return questionTitle;
}
public void setQuestionTitle(String questionTitle) {
this.questionTitle = questionTitle;
}
public List<QuestionsOption> getQuestionsOptions() {
return questionsOptions;
}
public void setQuestionsOptions(List<QuestionsOption> questionsOptions) {
this.questionsOptions = questionsOptions;
}
public Boolean getRequired() {
return required;
}
public void setRequired(Boolean required) {
this.required = required;
}
public String getAnswer() {
return answer;
}
public void setAnswer(String answer) {
this.answer = answer;
}
}
-----------------------------------rest.ListCaptureFrom.java-----------------------------------
package rest;
import java.util.List;
public class ListCaptureFrom {
private List<ListCaptureFrom_> listCaptureFrom = null;
private String status;
private Integer errorCode;
private String errorText;
public List<ListCaptureFrom_> getListCaptureFrom() {
return listCaptureFrom;
}
public void setListCaptureFrom(List<ListCaptureFrom_> listCaptureFrom) {
this.listCaptureFrom = listCaptureFrom;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public Integer getErrorCode() {
return errorCode;
}
public void setErrorCode(Integer errorCode) {
this.errorCode = errorCode;
}
public String getErrorText() {
return errorText;
}
public void setErrorText(String errorText) {
this.errorText = errorText;
}
}
-----------------------------------rest.ListCaptureFrom_.java-----------------------------------
package rest;
import java.util.List;
public class ListCaptureFrom_ {
private Integer formDataId;
private Integer establishmentId;
private Integer captureId;
private String captureTitle;
private String latitude;
private String longitude;
private String contactMasterId;
private Integer contactId;
private String contactQuestionsId;
private Integer appUserId;
private String createDate;
private List<ContactQuestion> contactQuestions = null;
private List<CaptureQuestion> captureQuestions = null;
public Integer getFormDataId() {
return formDataId;
}
public void setFormDataId(Integer formDataId) {
this.formDataId = formDataId;
}
public Integer getEstablishmentId() {
return establishmentId;
}
public void setEstablishmentId(Integer establishmentId) {
this.establishmentId = establishmentId;
}
public Integer getCaptureId() {
return captureId;
}
public void setCaptureId(Integer captureId) {
this.captureId = captureId;
}
public String getCaptureTitle() {
return captureTitle;
}
public void setCaptureTitle(String captureTitle) {
this.captureTitle = captureTitle;
}
public String getLatitude() {
return latitude;
}
public void setLatitude(String latitude) {
this.latitude = latitude;
}
public String getLongitude() {
return longitude;
}
public void setLongitude(String longitude) {
this.longitude = longitude;
}
public String getContactMasterId() {
return contactMasterId;
}
public void setContactMasterId(String contactMasterId) {
this.contactMasterId = contactMasterId;
}
public Integer getContactId() {
return contactId;
}
public void setContactId(Integer contactId) {
this.contactId = contactId;
}
public String getContactQuestionsId() {
return contactQuestionsId;
}
public void setContactQuestionsId(String contactQuestionsId) {
this.contactQuestionsId = contactQuestionsId;
}
public Integer getAppUserId() {
return appUserId;
}
public void setAppUserId(Integer appUserId) {
this.appUserId = appUserId;
}
public String getCreateDate() {
return createDate;
}
public void setCreateDate(String createDate) {
this.createDate = createDate;
}
public List<ContactQuestion> getContactQuestions() {
return contactQuestions;
}
public void setContactQuestions(List<ContactQuestion> contactQuestions) {
this.contactQuestions = contactQuestions;
}
public List<CaptureQuestion> getCaptureQuestions() {
return captureQuestions;
}
public void setCaptureQuestions(List<CaptureQuestion> captureQuestions) {
this.captureQuestions = captureQuestions;
}
}
-----------------------------------rest.QuestionsOption.java-----------------------------------
package rest;
public class QuestionsOption {
private Integer questionId;
private Integer optionId;
private String optionName;
private String optionValue;
public Integer getQuestionId() {
return questionId;
}
public void setQuestionId(Integer questionId) {
this.questionId = questionId;
}
public Integer getOptionId() {
return optionId;
}
public void setOptionId(Integer optionId) {
this.optionId = optionId;
}
public String getOptionName() {
return optionName;
}
public void setOptionName(String optionName) {
this.optionName = optionName;
}
public String getOptionValue() {
return optionValue;
}
public void setOptionValue(String optionValue) {
this.optionValue = optionValue;
}
}
Use this tool offline:Maven pluginGradle pluginAnt taskCLIJava API
Reference
Could some one please explain using the above how to actually make the conversion from json to the pojo's in the main class?
Any help would be appreciated