Announcement Announcement Module
No announcement yet.
restTemplate could not find message converter -- but this time it could be a bug Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • restTemplate could not find message converter -- but this time it could be a bug

    I have been using spring's restTemplate for while, but just learned a small lesson over the weekend. In fact, I think this is a bug, but like to hear experts' advice. Here is what happened.

    I defined a simple java Class:

    public class WebAccount extends ActivityStatus {
    	private int account_id=0;
    	private String login="";
    	private String password="";
    	private Boolean is_business=false;
    	private Boolean issue_invoice=false;
    	private int biller_id=0; 
    	private Boolean receive_invoice=true;
    	private int receiver_id=0; 
    	private String fname="";
    	private String lname="";
    	private String phone_number="";
    	private String email="";
    	private String addr_street1="";
    	private String addr_street2="";
    	private String addr_city="";
    	private String addr_state="";
    	private String addr_zip="";
    	private String business_name1=""; 
    	private String business_name2="";
    	private String business_name3="";
    	 getters and setters of all attributes...
    In the application, a method calls restTemplate, which returns a WebAccount:

    public WebAccount myProfilePage(WebKeys web_keys) {
    		String url = url_root + "myProfilePage/" + web_keys.getAccount_id();"url: " + url); 	
    		WebAccount web_account = (WebAccount) restTemplate.getForObject(url, WebAccount.class);
    		return web_account;
    The url points to a web service, defined by Spring's restFUL annotation, which is in separate body of codes:
    	public @ResponseBody
    	WebAccount myProfilePage(@PathVariable("acct_id") int account_id) {
    Back to the method "myProfilePage": just to be sure, I logged the url, and pasted it in a web browser. It returned a correct result. However, The restTemplate command in the method generated the following error message in test runs:

    org.springframework.web.client.RestClientException : Could not extract response: no suitable HttpMessageConverter found for response type [org.SandRiver.WebGateway.WebAccount] and content type [application/json]

    However, I do have a json message converter for restTemplate, defined in applicationContext.xml:
       <bean id="restTemplate" class="org.springframework.web.client.RestTemplate" scope="prototype">
            <property name="messageConverters">
    		<bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter"/>
    		<bean class="org.springframework.http.converter.FormHttpMessageConverter" />
    		<bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"/> 
    Eventually, I found out the following: in class WebAccount definition, if I remove setters for all 3 attributes of Boolean type (is_business, issue_invoices, receive_invoices), then everything is OK. Any setter for one of these attributes will bring out this exception.

    Did I do anything inappropriate, or is this a bug?


    John Zhu
    Last edited by [email protected]; May 22nd, 2013, 11:09 AM.