Sorry for answering my own post, but maybe this will help someone else. I don't know why I so frequently figure out something just after posting some place like this...
If I unmarshal to a JAXBElement instead of the type I'm looking for, then the JAXBElement's getValue() result can be cast to the complex type I started with and everyone is happy. This makes perfect sense now that I see it.
Thanks again
jsexton0 wrote:
I understand why the xmlrootelement annotation is not always generated. Just the same, I have to work with a schema for which JAXB does not (rightly) create the @XmlRootElement. What I need to do is make a string out of the data, then get the JAXB object back out latter.
To create the String, I added a "wrapper" like this:
marshaller.marshal(new JAXBElement(
new QName("
http://mydomain/schema/MyNamesape", "MyMessage"),
MyMessageType.class, request), sw);
However, the code Netbeans creates to convert this String back to an XML object gives me a java.lang.ClassCastException on the resulting Object. I've confirmed that the data (String) is intact, and is what I expect.
Is there a general approach to making a JAXB object with no @XmlRootElement pass through conversion to a String and back again?
Thanks
Thanks