spring mvc - Using Jaxb2Marshaller with multiple classes having same @XmlRootElement name -
i working on web service using spring-mvc , jaxb2marshaller.
i have 2 classes, both annotated same @xmlrootelement
name
@xmlrootelement(name="request") class foo extends astractrequest { } @xmlrootelement(name="request") class bar extends abstractrequest { }
all 3 classes (abstractrequest, foo, bar) included in classestobebound list in same order
now request uses bar works fine. 1 uses foo throws classcastexception exception during unmarshalling message bar cannot cast foo
the controller code this,
source source = new streamsource(new stringreader(body)); foo request = (foo) this.jaxb2marshaller.unmarshal(source);
i guess happening because bar kind of overriding foo since it's written after foo in list of classes bound in spring-servlet.xml file
however having multiple classes annotated @xmlrootelement(name="response")
, marshalling response doesn't give problem.
is there way specify class used jaxb2marshaller unmarshalling ?
you can pass class jaxb2marshaller before unmarshal:
source source = new streamsource(new stringreader(body)); jaxb2marshaller.setmappedclass(foo.class); foo request = (foo) jaxb2marshaller.unmarshal(source);
Comments
Post a Comment