Announcement Announcement Module
Collapse
No announcement yet.
No Suitable HttpMessageConverter exception on calling postForObject for custom object Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • No Suitable HttpMessageConverter exception on calling postForObject for custom object

    Hi,

    I am trying to post a custom object using postForObject method. It throws below exception:

    org.springframework.web.client.RestClientException : Could not write request: no suitable HttpMessageConverter found for request type [com.test.MyClass]

    The calling part is as below:

    private RestTemplate restTemplate = new RestTemplate(true);
    restTemplate.getMessageConverters().add(new FormHttpMessageConverter());
    restTemplate.getMessageConverters().add(new SimpleXmlHttpMessageConverter());
    String response = restTemplate.postForObject(url, myClass, String.class);

    myClass in an object of MyClass. The service expects xml representation of myClass object.

    The MyClass definition is as below:
    public class MyClass {

    private long id_;
    private String info_;
    private long token_;

    public long getId() {return id_;}
    public String getInfo() {return info_;}
    public long getToken() {return token_;}

    public void setId(long id_) {this.id_ = id_;}
    public void setInfo(String info_) {this.info_ = info_;}
    public void setToken(long token_) {this.token_ = token_;}
    }

    I found similar approach on Spring Andorid blog for JSON data, where JSON specific converters are used. But thats not working here. Kindly suggest!

    Thanks.

  • #2
    As, it looks like the HttpMessageConverter is not suitable, can someone suggest me how to write a custom HttpMessageConverter which can work with myClass object?

    Comment

    Working...
    X