'Generic restTemplateExchange with generic responseType

I would like to create a own generic method that calls the restTemplate.exchange. In particular I would like that the signature of this generic method to be :

protected <T> ResponseEntity<T> genericExchange(String uri, HttpMethod method, @Nullable HttpEntity<?> requestEntity, -->responseType<--)

I would differentiate what exchange method call according to "responseType"

  • if responseType is Class< T> I call * exchange(URI url, HttpMethod method, HttpEntity<?> requestEntity, Class< T> responseType)*
  • if responseType is ParameterizedTypeReference< T> I call * exchange(URI url, HttpMethod method, HttpEntity<?> requestEntity, ParameterizedTypeReference< T> responseType)*


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source