resttemplate getForObject map responsetype

RestTemplate has a method named exchange that takes an instance of ParameterizedTypeReference as parameter.

To make a GET request that returns a java.util.Map, just create an instance of an anonym class that inherits from ParameterizedTypeReference.

ParameterizedTypeReference<Map<String, String>> responseType =
        new ParameterizedTypeReference<>() {};

You can then invoke the exchange method:

RequestEntity<Void> request = RequestEntity.get("http://example.com/foo")
                 .accept(MediaType.APPLICATION_JSON).build();
Map<String, String> jsonDictionary = restTemplate.exchange(request, responseType).getBody();

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)