I'm consuming a REST API that can answer in this manner:
[
{
"status":"1",
"report":{
"name":"John",
"job":"Software Developer"
}
},
{
"status":"0",
"report":"John not found"
}
]
As you can see above the value of report
field can be both a JSON Object and a String. This is the reason why I am in trouble parsing it as POJO.
For instance I have my OutcomeResponse
POJO:
public class OutcomeResponse {
private String status;
private Report report;
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public Report getReport() {
return report;
}
public void setReport(Report report) {
this.report = report;
}
}
Where Report
is:
public class Report {
private String name;
private String job;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getJob() {
return job;
}
public void setJob(String job) {
this.job = job;
}
}
Now I'm executing a POST as follow:
OutcomeResponse [] response = client.executePost(endpoint, headers, body, OutcomeResponse [].class);
But I have an exception: I have a string in report instead of an Object as expected:
Expected BEGIN_OBJECT but was STRING at line 1 column 25 path $[0].value
How can I solve this problem?