Reputation: 4050
I am having trouble correctly creating a model / entity for a Spring MVC RestTemplate.exchange
request which will correspond to this JSON response:
{
"resourceLookup": [
{
"version": 0,
"permissionMask": 1,
"creationDate": "2017-08-16T12:52:30",
"updateDate": "2017-08-16T12:52:30",
"label": "",
"description": "",
"uri": "",
"resourceType": ""
},
{
"version": 5,
"permissionMask": 1,
"creationDate": "2017-08-16T11:34:04",
"updateDate": "2017-08-17T08:27:02",
"label": "",
"description": "",
"uri": "",
"resourceType": ""
}
]
}
I've created the following models:
Report class (getters/setters omitted):
public class Report implements Serializable {
private Long version;
private String permissionMask;
private Date creationDate;
private Date updateDate;
private String label;
private String description;
private String url;
private String resourceType;
public Report() {
}
ResourceLookup class:
public class ResourceLookup implements Serializable {
List<Report> reports;
public ResourceLookup() {
}
public List<Report> getReports() {
return reports;
}
public void setReports(List<Report> reports) {
this.reports = reports;
}
}
In the end the response is reports=null
. If I return a String
with this code everything is fine:
restTemplate.exchange(serverUrl, HttpMethod.GET, httpEntity, String.class).getBody();
I need to correctly map it to the models so that I can return a correctly formatted JSON to my other API's.
Upvotes: 1
Views: 96
Reputation: 3423
Try it this way:
public class ResourceLookup implements Serializable {
List<Report> resourceLookup;
public ResourceLookup() {
}
public List<Report> getResourceLookup() {
return resourceLookup;
}
public void setResourceLookup(List<Report> resourceLookup) {
this.resourceLookup = resourceLookup;
}
}
Upvotes: 1