I have generated java classes using xjc
from an xsd where the root element was A
of type AType
.
The root element generated by jaxb is AType
& no class A
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:
JAXBContext jaxbContext = JAXBContext.newInstance(Class.forName("AType"));
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
AType aType = (AType) unmarshaller.unmarshal(new ByteArrayInputStream(xmlString.getBytes()));
Exception:
java.lang.ClassCastException: javax.xml.bind.JAXBElement
Same code for other cases execute properly and successfully deserialize.
How can I find unmarshal()
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 jaxbElement
but it was not very useful!