The getForObject method fetches the data for the given response type from the given URL template using HTTP GET method. To fetch data for the given key properties from URL template we can pass Object Varargs and Map to the getForObject method. The getForObject returns directly the object of the given response type.
First, to access the getForObject method we need a RestTemplate object.
RestTemplate restTemplate = new RestTemplate();
To access the getForObject() method
restTemplate. getForObject(URI url, Class<T> responseType)
Here, url: URL to fetch data from
responseType: Type of object returned by getForObject method.
e.g. If the response is returning the Employee objects then we can define getForObject() like this:
Employee[] employees= restTemplate.getForObject(url, Employee[].class);
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article