I have two classes annotated for jaxb that share the same root element name. When using the RestTemplate to unmarshall each type separately, it appears the Jaxb2RootElementHttpMessageConverter ignores the responseType class and tries to unmarshall the xml response as one of its choosing. As a result, the unmarshaller isn't choosing the correct one, as both classes are registered with the jaxbcontext, and leads to a ClassCastException. Is this a bug?
Code:public abstract class ResponseBase { } @XmlRootElement(name="response") public class ResponseA extends ResponseBase { } @XmlRootElement(name="response") public class ResponseB extends ResponseBase { } @Test public void test() { RestTemplate rest = new RestTemplate(); ResponseA response = rest.getForObject("url", ResponseA.class); // causes ClassCastException ResponseB response = rest.getForObject("url2", ResponseB.class); }


Reply With Quote
