When invoking a web service using RestTemplate:-
restTemplate.getForObject("http://www.server.com/api", Bean[].class));
… the following exception occurs:-
Exception in thread "main" org.springframework.web.client.RestClientException:
Could not extract response: no suitable HttpMessageConverter found for response
type [class [LMyBean;] and content type [application/json;charset=UTF-8]
at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:1110)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:1572)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:1530)
at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:1237)
SOLUTION
If the content type is JSON, add the following dependency:-
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.6.0</version>
</dependency>
restTemplate.getForObject("http://www.server.com/api", Bean[].class));
… the following exception occurs:-
Exception in thread "main" org.springframework.web.client.RestClientException:
Could not extract response: no suitable HttpMessageConverter found for response
type [class [LMyBean;] and content type [application/json;charset=UTF-8]
at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:1110)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:1572)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:1530)
at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:1237)
SOLUTION
If the content type is JSON, add the following dependency:-
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.6.0</version>
</dependency>
Hello,
ReplyDeletecould you explain the reason of this solution? It works fine, but I would like to understand it. Thanks
still did not solve problem for me....
ReplyDeleteThis piece of code solved my problem...
ReplyDeleteList> messageConverters = new ArrayList>();
MediaType mediaTypeJson = new MediaType("application", "json");
MediaType mediaTypeXml = new MediaType("application", "xml");
MediaType mediaTypeText = new MediaType("plain", "text");
List supportedMediaTypes = new ArrayList(
Arrays.asList(mediaTypeJson, mediaTypeXml, mediaTypeText));
MappingJacksonHttpMessageConverter jacksonConverter = new MappingJacksonHttpMessageConverter();
jacksonConverter.setSupportedMediaTypes(supportedMediaTypes);
messageConverters.add(jacksonConverter);
template.setMessageConverters(messageConverters);
Thanks,
Mahesh
None of the above solutions worked for me.
ReplyDelete