Spring restTemplate.postForEntity(or postForObject) gives error "no suitable HttpMessageConverter" in Stand alone Java application

17,044

Solution 1

Funny, I just answered similar question...

Nevertheless you may want check great Spring Reference Manual, particularly this fragment, documentation, IBM Dev blog post and RestTemplate example on SpringSource Blog (written when ).

From SpringSource Blog post:

HttpMessageConverters

Objects passed to and returned from the methods getForObject(), postForLocation(), and put() and are converted to HTTP requests and from HTTP responses by HttpMessageConverters. Converters for the main mime types and Java types are registered by default, but you can also write your own converter and plug it in the RestTemplate.

Also, IBM blog post here mentions common HttpMessageConverter implementations, you probably will use Marshalling (response in XML) or MappingJackson (for JSON) one.

Solution 2

Most likely that REST service you called would have failed and postForObject() returned null. You need to check for errors using ResponseErrorHandler implementations.

Share:
17,044
Maharsh
Author by

Maharsh

Updated on August 22, 2022

Comments

  • Maharsh
    Maharsh over 1 year

    I have stand alone Java Application with Spring 3.0. I am calling REST service "post" method call with 4 integer parameters. While calling restTemplate.postForEntity(), I am getting error "no suitable HttpMessageConverter found for request type". Is it require to set any messageConverter in restTemplate ? i don't find any sample on net.