This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

exception when invoking methods on twitterTemplate

I am developing an example for accessing Twitter. All goes well when I do the oAuth "dance". At the end when I try to invoke the available methods on the TwitterTemplate I get:

Exception in thread "main" org.springframework.web.client.RestClientException : Could not extract response: no suitable HttpMessageConverter found for response type [java.util.Map] and content type [application/json;charset=utf-8]
at org.springframework.web.client.HttpMessageConverte rExtractor.extractData(HttpMessageConverterExtract or.java:77)
at org.springframework.web.client.RestTemplate$Respon seEntityResponseExtractor.extractData(RestTemplate .java:619)
at org.springframework.web.client.RestTemplate$Respon seEntityResponseExtractor.extractData(RestTemplate .java:1)
at org.springframework.web.client.RestTemplate.doExec ute(RestTemplate.java:446)
at org.springframework.web.client.RestTemplate.execut e(RestTemplate.java:401)
at org.springframework.web.client.RestTemplate.postFo rEntity(RestTemplate.java:302)
at org.springframework.social.twitter.TwitterTemplate .updateStatus(TwitterTemplate.java:134)
at xx.xxxxxxx.SpringSocialApp.TwitterApp.main(Twitter App.java:121)

I am getting this when I do both:

Code:

String profileId = twitterTemplate.getProfileId();

and

Code:

twitterTemplate.updateStatus("yupiiiiii!");

I found this post where one of the users mentions doing a try-catch block and ignoring the exception. This would go well for the updateStatus method (since I can see that the status gets updated). But creates a problem when you need to get something from the twitter server.

A wild guess: since the exception is all about not being able to resolve application/json content type, and on the other hand I cannot see the Jackson converter in the available converters, does this mean I am missing a library? Is spring-social-core.jar enough or should I include some other libraries in the project?

Comment

Yes, Jackson is a required because the data coming back from Twitter is in JSON format.

Under the covers of TwitterTemplate is RestTemplate, which uses implementations of HttpMessageConverter to convert data coming back from a REST service into some type that the caller asks for. There will only be a JSON message converter if Jackson is in the classpath. Otherwise, without a suitable JSON message converter registered, you'll get an exception saying that there's no suitable message converter to convert between application/json and whatever type RestTemplate is asked to give back.

Comment

<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>[1.0,2.0)</version> <!-- 1.0 <= x < 2.0 so all versions higher than 1.0 including 1.0 but lower
than (and excluding) 2.0, since the version of jackson 2.0 might not be compatible. -->
</dependency>