There is a RestFull method that return a List of Menu objects
public ResponseEntity<List<Menu>> getMenus() {
..
}
But I don't know how to get them from the RestTemplate, getting the class from ResponseEntity>
ResponseEntity<List<Menu>> response = restTemplate
.exchange("http://127.0.0.1:8080/elcor/api/users/1/menus", HttpMethod.GET, entity, ResponseEntity<List<Menu>>.getClass());
setContentType(MediaType. APPLICATION_JSON); Employee employee = new Employee(); HttpEntity<Employee> entity = new HttpEntity<Employee>(employee, headers); ResponseEntity<String> result = restTemplate. exchange(uri, HttpMethod. GET, entity, String.
RestTemplate provides a synchronous way of consuming Rest services, which means it will block the thread until it receives a response. RestTemplate is deprecated since Spring 5 which means it's not really that future proof. First, we create a Spring Boot project with the spring-boot-starter-web dependency.
For example, the method getForObject() will perform a GET and return an object. getForEntity() : executes a GET request and returns an object of ResponseEntity class that contains both the status code and the resource as an object. getForObject() : similar to getForEntity() , but returns the resource directly.
Try use ParameterizedTypeReference
ResponseEntity<List<Menu>> response = restTemplate
.exchange("URI", HttpMethod.GET, entity, new ParameterizedTypeReference<List<Menu>>() {
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With