I'm trying to consume a HAL-based REST service with the RestTemplate class. The response body looks like this:
{
"_embedded": {
"school:teachers": [
{
"name": "Adams",
"state": "CA",
"_links": {
"self": {
"href": "http://localhost:8080/api/teachers/1"
}
}
},
{
"name": "Barnes",
"state": "FL",
"_links": {
"self": {
"href": "http://localhost:8080/api/teachers/2"
}
}
},
{
"name": "Armstrong",
"state": "GA",
"_links": {
"self": {
"href": "http://localhost:8080/api/teachers/3"
}
}
}
]
},
"_links": {
"curies": [
{
"href": "http://localhost:8080/docs/html5/{rel}.html",
"name": "school",
"templated": true
}
]
}
}
The Teacher class looks like this:
public class Teacher {
private String name;
private String state;
// getters and setters...
}
The return type of the REST service for GET method is ResponseEntity<Resources<Resource<Component>>>. Therefore my request in the client code looks like this:
...
RestTemplate restTemplate = new RestTemplate();
Map<String, Object> dummy = new HashMap<>();
HttpEntity<String> httpEntity = getHttpEntity();
ResponseEntity<Resources<Resource<Teacher>>> response = restTemplate.exchange(url,
HttpMethod.GET,
httpEntity,
new ParameterizedTypeReference<Resources<Resource<Teacher>>>() {});
Resources<Resource<Teacher>> resources = response.getBody();
...
When i make the request with the response type ParameterizedTypeReference the content of the response is empty. When i do it with String i retrieve the content list.
How should i do the request to retrieve it with the response type ParameterizedTypeReference to map it directly in the POJO?