Affects: If this is not the right place for this issue, please let me know.


Hello

I think that exchange, getForEntity, postForEntity function which is in RestTemplate, Spring web Framework is designed to receive ResponseEntities from each http method request like below. And there's no guide in docs ever, so users are using same purpose depending on their needs.

@Override
    public <T> ResponseEntity<T> exchange(String url, HttpMethod method,
            @Nullable HttpEntity<?> requestEntity, Class<T> responseType, Object... uriVariables)
            throws RestClientException {

        RequestCallback requestCallback = httpEntityCallback(requestEntity, responseType);
        ResponseExtractor<ResponseEntity<T>> responseExtractor = responseEntityExtractor(responseType);
        return nonNull(execute(url, method, requestCallback, responseExtractor, uriVariables));
    }
@Override
    public <T> ResponseEntity<T> getForEntity(String url, Class<T> responseType, Object... uriVariables)
            throws RestClientException {

        RequestCallback requestCallback = acceptHeaderRequestCallback(responseType);
        ResponseExtractor<ResponseEntity<T>> responseExtractor = responseEntityExtractor(responseType);
        return nonNull(execute(url, HttpMethod.GET, requestCallback, responseExtractor, uriVariables));
    }
@Override
    public <T> ResponseEntity<T> postForEntity(String url, @Nullable Object request,
            Class<T> responseType, Object... uriVariables) throws RestClientException {

        RequestCallback requestCallback = httpEntityCallback(request, responseType);
        ResponseExtractor<ResponseEntity<T>> responseExtractor = responseEntityExtractor(responseType);
        return nonNull(execute(url, HttpMethod.POST, requestCallback, responseExtractor, uriVariables));
    }

However, Spring Web supports ParameterizedTypeReference for mapping response to any Type like Collections in exchange. On the other hand, getForEntity, postForEntity are not supported.

@Override
    public <T> ResponseEntity<T> exchange(RequestEntity<?> entity, ParameterizedTypeReference<T> responseType)
            throws RestClientException {

        Type type = responseType.getType();
        RequestCallback requestCallback = httpEntityCallback(entity, type);
        ResponseExtractor<ResponseEntity<T>> responseExtractor = responseEntityExtractor(type);
        return nonNull(doExecute(resolveUrl(entity), entity.getMethod(), requestCallback, responseExtractor));
    }

Therefore request for applying on getForEntity, postForEntity using ParameterizedTypeReference. Spring is designed to allow programmers to use freely without limitation, so I personally think adaptation is required.

Comment From: hubtwork

Implements that function what i mentioned in issue and create PR on.

Comment From: rstoyanchev

I'm closing this as per my comment under the PR. Please keep in mind that if you plan to submit a PR from the start, then you don't need to create an issue. When you create both, we close the issue and continue discussion on the PR.