1st
{
"data": {
"weather": [
{
"location": "location1",
"condition": "condition1",
},
{
"location": "location2",
"condition": "condition2",
}
],
"total": 2
},
"sucess": true
}
2nd
{
"data": {
"syncRequired": true,
"totalOfLocations": 0
},
"success": true
}
These 2 blocks are generally the response that I get from my API calls, and how I have been parsing it is by creating 2 different POJO classes for each response. Generally this is how it should look like for the 2nd block of json response.
public class JsonResponse {
@SerializedName("success")
@Expose
private Boolean success;
@SerializedName("data")
@Expose
private DataSync data;
public Boolean getSuccess() {
return success;
}
public void setSuccess(Boolean success) {
this.success = success;
}
public DataSync getDataSync() {
return data;
}
public void setDataSync() {
this.data = data;
}
}
and then parse inside the data key likewise
public class DataSync{
@SerializedName("syncRequired")
@Expose
private Boolean syncRequired;
@SerializedName("totalOfLocations")
@Expose
private Integer totalOfLocations;
public Boolean isSyncRequired() {
return syncRequired;
}
public void setSyncRequired(Boolean success) {
this.syncRequired= syncRequired;
}
public Integer getTotalOfLocations() {
return totalOfLocations;
}
public void setTotalOfLocations() {
this.totalOfLocations= totalOfLocations;
}
}
My aim is to use a single class of JsonResponse to parse every response that I get, and map the Data to their relevant Data classes for further parsing. Let me know if you need more information so that its easier to help me with my questions. Thanks in advance.