@@ -166,16 +166,18 @@ public ResponseErrorHandler getErrorHandler() {
166
166
public <T > T getForObject (String url , Class <T > responseType , String ... urlVariables ) throws RestClientException {
167
167
168
168
checkForSupportedMessageConverter (responseType );
169
+ List <HttpMessageConverter <T >> supportedMessageConverters = getSupportedMessageConverters (responseType );
169
170
return execute (url , HttpMethod .GET , new GetCallback <T >(responseType ),
170
- new HttpMessageConverterExtractor <T >(responseType ), urlVariables );
171
+ new HttpMessageConverterExtractor <T >(responseType , supportedMessageConverters ), urlVariables );
171
172
}
172
173
173
174
public <T > T getForObject (String url , Class <T > responseType , Map <String , String > urlVariables )
174
175
throws RestClientException {
175
176
176
177
checkForSupportedMessageConverter (responseType );
178
+ List <HttpMessageConverter <T >> supportedMessageConverters = getSupportedMessageConverters (responseType );
177
179
return execute (url , HttpMethod .GET , new GetCallback <T >(responseType ),
178
- new HttpMessageConverterExtractor <T >(responseType ), urlVariables );
180
+ new HttpMessageConverterExtractor <T >(responseType , supportedMessageConverters ), urlVariables );
179
181
}
180
182
181
183
// HEAD
@@ -381,37 +383,6 @@ public void doWithRequest(ClientHttpRequest httpRequest) throws IOException {
381
383
}
382
384
}
383
385
384
- /**
385
- * Response extractor that uses the registered {@linkplain HttpMessageConverter entity converters}
386
- * to convert the response into a type <code>T</code>.
387
- */
388
- private class HttpMessageConverterExtractor <T > implements ResponseExtractor <T > {
389
-
390
- private final Class <T > responseType ;
391
-
392
- private HttpMessageConverterExtractor (Class <T > responseType ) {
393
- this .responseType = responseType ;
394
- }
395
-
396
- public T extractData (ClientHttpResponse response ) throws IOException {
397
- MediaType contentType = response .getHeaders ().getContentType ();
398
- if (contentType == null ) {
399
- throw new RestClientException ("Cannot extract response: no Content-Type found" );
400
- }
401
- for (HttpMessageConverter <T > messageConverter : getSupportedMessageConverters (this .responseType )) {
402
- for (MediaType supportedMediaType : messageConverter .getSupportedMediaTypes ()) {
403
- if (supportedMediaType .includes (contentType )) {
404
- return messageConverter .read (this .responseType , response );
405
- }
406
- }
407
- }
408
- throw new RestClientException (
409
- "Could not extract response: no suitable HttpMessageConverter found for response type [" +
410
- this .responseType .getName () + "] and content type [" + contentType + "]" );
411
- }
412
-
413
- }
414
-
415
386
/** Response extractor that extracts the response {@link HttpHeaders}. */
416
387
private static class HeadersExtractor implements ResponseExtractor <HttpHeaders > {
417
388
0 commit comments