How can I unmarshal a message that was marshalled using a QName local part different then what is expected?
My example is below:
Given an object to unmarshal that has been created using a marshal method such as
marshaller.marshal( new JAXBElement(
new QName("urn:somenamespace","DifferentNameMessage"),
OriginalMessageType.class,
originalMsg),
result);
(As I understand this code snippet, the QName is indicating to make the root element use a substitue name tag other than what is specified in the original schema. Essentially using a substitute name method. For instance, in the QName above the original tag would have been "NameMessage" but the message was marshalled using local part "DifferentNameMessage".)
I would normally use a method of unmarshalling such as:
String xmlString = convertStreamToString(in);
final StringReader xmlReader = new StringReader(xmlString);
final StreamSource xmlSource = new StreamSource(xmlReader);
JAXBContext jaxbContext = JAXBContext.newInstance(OriginalMessageType.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
JAXBElement ret = null;
ret = unmarshaller.unmarshal(xmlSource, OriginalMessageType.class);
But, if I use this method then the JAXBElement ret name is for the QName that was use to marshalled it, yet the DeclaredType is for OriginalMessageType.class and the unmarshalled message contains null element values for the expected sub-elements, even though the original message contains valid values for these sub-elements.
i am wondering if it is possible to specifiy the substitute QName during unmarshalling to indicate that it is a substitute and then to use the original tag in its place?