Note that there are some explanatory texts on larger screens.

plurals
  1. POandroid RestClientException: no suitable HttpMessageConverter found
    text
    copied!<p>I am using <code>spring android rest template</code> and trying to convert a JSON response into a java class as shown <a href="http://static.springsource.org/spring-android/docs/1.0.x/reference/html/rest-template.html#rest-template-examples" rel="noreferrer">here</a>.</p> <p>Here is my snippet trying to do the work:</p> <pre><code> RestTemplate restTemplate = new RestTemplate(); restTemplate.getMessageConverters().add(new MappingJacksonHttpMessageConverter()); //I have already tried to manually setting converters with no luck //List&lt;HttpMessageConverter&lt;?&gt;&gt; messageConverters = new ArrayList&lt;HttpMessageConverter&lt;?&gt;&gt;(); //messageConverters.add(new MappingJacksonHttpMessageConverter()); //messageConverters.add(new FormHttpMessageConverter()); //messageConverters.add(new StringHttpMessageConverter()); //restTemplate.setMessageConverters(messageConverters); Result result = restTemplate.getForObject(url, Result.class); </code></pre> <p>I think I have done everything required as it is told in the document:</p> <ul> <li>I have following jars in my classpath <ul> <li>jackson-all-1.7.6.jar</li> <li>spring-android-rest-template-1.0.0.M2.jar</li> </ul></li> <li>the <code>url</code> really returns a JSON object.</li> <li>My <code>Result</code> class is a POJO with all the required fields</li> </ul> <p>Basically having the <code>Jackson dependencies</code> in my classpath must be enough to get it work as it says:</p> <blockquote> <p>The MappingJacksonHttpMessageConverter is conditionally loaded when you create a new RestTemplate instance. If the Jackson dependencies are found in your classpath, the message converter will be automatically added and available for use in REST operations.</p> </blockquote> <p>So what I am missing here, what I am doing wrong?</p> <p>Thanks</p> <p>Full exception can be found here:</p> <pre><code>04-20 04:25:52.706: ERROR/AndroidRuntime(9638): FATAL EXCEPTION: main 04-20 04:25:52.706: ERROR/AndroidRuntime(9638): java.lang.IllegalStateException: Could not execute method of the activity 04-20 04:25:52.706: ERROR/AndroidRuntime(9638): at android.view.View$1.onClick(View.java:2083) 04-20 04:25:52.706: ERROR/AndroidRuntime(9638): at android.view.View.performClick(View.java:2421) 04-20 04:25:52.706: ERROR/AndroidRuntime(9638): at android.view.View$PerformClick.run(View.java:8869) 04-20 04:25:52.706: ERROR/AndroidRuntime(9638): at android.os.Handler.handleCallback(Handler.java:587) 04-20 04:25:52.706: ERROR/AndroidRuntime(9638): at android.os.Handler.dispatchMessage(Handler.java:92) 04-20 04:25:52.706: ERROR/AndroidRuntime(9638): at android.os.Looper.loop(Looper.java:143) 04-20 04:25:52.706: ERROR/AndroidRuntime(9638): at android.app.ActivityThread.main(ActivityThread.java:5068) 04-20 04:25:52.706: ERROR/AndroidRuntime(9638): at java.lang.reflect.Method.invokeNative(Native Method) 04-20 04:25:52.706: ERROR/AndroidRuntime(9638): at java.lang.reflect.Method.invoke(Method.java:521) 04-20 04:25:52.706: ERROR/AndroidRuntime(9638): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 04-20 04:25:52.706: ERROR/AndroidRuntime(9638): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 04-20 04:25:52.706: ERROR/AndroidRuntime(9638): at dalvik.system.NativeStart.main(Native Method) 04-20 04:25:52.706: ERROR/AndroidRuntime(9638): Caused by: java.lang.reflect.InvocationTargetException 04-20 04:25:52.706: ERROR/AndroidRuntime(9638): at xxx.SamplePageActivity.doRest(SamplePageActivity.java:83) 04-20 04:25:52.706: ERROR/AndroidRuntime(9638): at java.lang.reflect.Method.invokeNative(Native Method) 04-20 04:25:52.706: ERROR/AndroidRuntime(9638): at java.lang.reflect.Method.invoke(Method.java:521) 04-20 04:25:52.706: ERROR/AndroidRuntime(9638): at android.view.View$1.onClick(View.java:2078) 04-20 04:25:52.706: ERROR/AndroidRuntime(9638): ... 11 more 04-20 04:25:52.706: ERROR/AndroidRuntime(9638): Caused by: org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [[Lxxx.SamplePageActivity$Result;] and content type [application/json;charset=UTF-8] 04-20 04:25:52.706: ERROR/AndroidRuntime(9638): at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:77) 04-20 04:25:52.706: ERROR/AndroidRuntime(9638): at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:449) 04-20 04:25:52.706: ERROR/AndroidRuntime(9638): at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:404) 04-20 04:25:52.706: ERROR/AndroidRuntime(9638): at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:202) 04-20 04:25:52.706: ERROR/AndroidRuntime(9638): ... 15 more </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload