ClassCastException while Unmarshalling XML with JAXB

Vildosola

New Member
I have generated java classes using \[code\]xjc\[/code\] from an xsd where the root element was \[code\]A\[/code\] of type \[code\]AType\[/code\].The root element generated by jaxb is \[code\]AType\[/code\] & no class \[code\]A\[/code\] has been generated.When I try to unmarshall an xml corresponding to that xsd and cast the JaxbElement it is throwing a cast exception:Snippet:\[code\]JAXBContext jaxbContext = JAXBContext.newInstance(Class.forName("AType"));
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
AType aType = (AType) unmarshaller.unmarshal(new ByteArrayInputStream(xmlString.getBytes()));\[/code\]Exception:\[code\]java.lang.ClassCastException: javax.xml.bind.JAXBElement\[/code\]Same code for other cases execute properly and successfully deserialize.How can I find \[code\]unmarshal()\[/code\] gives me object of what type? I have no clue what's going wrong in this situation, I've tried printing out fields in that \[code\]jaxbElement\[/code\] but it was not very useful!
 
Back
Top