Results 1 to 1 of 1

Thread: Marshalling entities with the same root name

  1. #1
    Join Date
    Oct 2011
    Posts
    27

    Default Marshalling entities with the same root name

    Hello.

    I am in a project where we're building synchorization services to an external system using RESTful web service calls through RestTemplate. The external system gives us three entities: places, events and members, through three different uri's. The problem is that the XML-structure for all three entities has the top-level tag "<xml>", so we end up having three jaxb2 classes with @XmlRootElement(name="xml") which causes a problem when the information is marshalled. The marshaller fails because it can't figure out which <xml>-structure is coming.

    We are using Http message converters with a jaxb2 marshaller set up like this:
    Code:
    	<beans:bean id="jaxb2Marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
    	    <beans:property name="classesToBeBound">
    	        <beans:list>
    	            <beans:value>com.mycompany.mysystem.model.jaxb.Member</beans:value>
    	            <beans:value>com.mycompany.mysystem.model.jaxb.Xml</beans:value>
    	            <beans:value>com.mycompany.mysystem.model.jaxb.Gpx</beans:value>
    	            <beans:value>com.mycompany.mysystem.model.jaxb.EventXml</beans:value>
    	            <beans:value>com.mycompany.mysystem.model.User</beans:value>
    	        </beans:list>
    	    </beans:property>
    	</beans:bean>
    This is how the web service call is made:
    Code:
        	String url = ConstantHelper.MY_URI_BASE + ConstantHelper.MY_PLACES_URL + urlParameters;
        	EventXml eventList = restTemplate.getForObject(url, EventXml.class);
    The preferred solution would of course be to solve the issue at the root and deliver xml with different tag names or have them qualified with name spaces, but there is now way we can have any changes made there.

    So can someone please suggest a good way to solve this?
    Last edited by weedobooty; Apr 30th, 2012 at 04:27 AM. Reason: Added code snippet

Posting Permissions

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