Get model object with RestTemplate

I try to load an object model, in a List, with a org.springframework.web.client.RestTemplate.RestTemplate() and his method:

List<Document>  l = restTemplate.getForEntity("url", "class")

In other hand there is the webService implemented with springWeb like this:

@RequestMapping(value = "/documents", method = RequestMethod.GET)
public ResponseEntity<ServiceResponse> list() {
    LOGGER.info(String.format("CALL : /rest/documents"));

    return new ResponseEntity<ServiceResponse>(new ServiceResponse(Code.OK, documentService.list()), HttpStatus.OK);
}

How to extract the list from the responseEntity<> returned by restTemplate.getForEntity?

The situation evolve. I did this:

ResponseEntity<ServiceResponse> quote = restTemplate.getForEntity("https://apps.athena-software.fr/edocsol-ground-backend/rest/documents",
                ServiceResponse.class);

        List l = (List) quote.getBody().getResponse();

I have now a List with each key of Map is a field of the object "Document", i need to do a converter in order to get a List"Document" from the List"Map" you think or there is something that do it?

Upvotes: 0

Views: 842

Answers (1)

Thomas Uhrig
Thomas Uhrig

Reputation: 31605

The list is wrapped into a ServiceResponse, so you need to map to this class:

ServiceResponse serviceResponse = restTemplate.getForEntity("url", ServiceResponse.class);
List<Document> list = serviceResponse.getList(); // or whatever the method is called

Upvotes: 1

Related Questions