Results 1 to 3 of 3

Thread: RestTemplate / JAXB issue

  1. #1
    Join Date
    Mar 2007
    Posts
    4

    Default RestTemplate / JAXB issue

    Hi
    I am using RestTemplate and JAXB as a message converter. (org.springframework.oxm.jaxb.Jaxb2Marshaller)
    I am calling:
    Code:
    		// I have a POJO named API which is generated by xjc from a xsd
                    // RHEVM_API  is a URL
                   API api =  restTemplate.getForObject(RHEVM_API, API.class);
    As a result I get a ClassCastException telling that I try to cast JAXBElement to API.
    After a debug session I understood that the 'getForObject' call return a JAXBElement which contains the API POJO inside. Calling the getValue() method of this JAXBelement return the API POJO.

    Code:
    		JAXBElement<?> jaxbElement = restTemplate.getForObject(RHEVM_API, JAXBElement.class);
    		return (API)jaxbElement.getValue();
    Looking at RestTemplate examples I see that no one has to do this 'trick'.
    I know I am missing something here :-(
    What is it?


    Thanks

    Avishay

  2. #2
    Join Date
    Nov 2011
    Posts
    2

    Default

    I also facing the same prob...

    Final Year IEEE Projects

  3. #3
    Join Date
    Jan 2009
    Location
    Huntington Beach, CA
    Posts
    718

    Default

    Just out of curiosity. I thought the RestTemplate gives you a default HttpMessageConverter, that already know how to convert using JAXB, where all you needed was the JAXB jars on the classpath, and your entity to have JAXB mapping annotations and then everything just worked automatically.

    That is probably what you see in the examples. They aren't changing out the HttpMessageConverter that the Template by default uses.

    Try it out. I could be completely wrong, as I have very little experience with the RestTemplate.

    Mark

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •