0

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?

1 Answer 1

1

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
3
  • This don't work with this exception, "Cannot cast from ResponseEntity<ServiceResponse> to ServiceResponse" Nov 23, 2015 at 9:57
  • Nice! So make ResponseEntity<ServiceResponse> entity = restTemplate.getForEntity("url", ResponseEntity.class); and entity.getBody(). Nov 23, 2015 at 10:14
  • Yes, the situation evolved, i edited the questions, thanks. Nov 23, 2015 at 10:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.