Embracing the Messiness in Search of Epic Solutions

Rest Template: Could Not Extract Response – No Suitable HttpMessageConverter Found for Response Type [X] and Content Type [application/json;charset=UTF-8]

Posted

in

PROBLEM

When invoking a web service using RestTemplate:-

restTemplate.getForObject("http://server/api", MyBean[].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:110)
	at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:572)
	at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:530)
	at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:237)

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>

Tags:

Comments

6 responses to “Rest Template: Could Not Extract Response – No Suitable HttpMessageConverter Found for Response Type [X] and Content Type [application/json;charset=UTF-8]”

  1. Ramesh Avatar
    Ramesh

    It didn’t worked for me. Still getting same exception

  2. Farzin Avatar
    Farzin

    Thanks a lot. I did a lot of searches to find your solution to my problem even if the cause of mine was not exactly the same (I had to remove test from pom.xml)

    1. Farzin Avatar
      Farzin

      \test\ in pom.xml had to be removed.

  3. maher Avatar
    maher

    hi please where did you find test , i try the solution of this post but it doesn’t work for me . Can any one help me .

  4. […] I was having a very similar problem, and it turned out to be quite simple; my client wasn’t including a Jackson dependency, even though the code all compiled correctly, the auto-magic converters for JSON weren’t being included. See this RestTemplate-related solution. […]

  5. Juan Chavez Avatar

    In my case work it fine , just for the record, im using java 6

Leave a Reply