title: JAXB: Unmarshal a message using QName?
body: <p>How can I unmarshal a message that was marshalled using a QName local part different then what is expected?</p>
  
  <p>My example is below:</p>
  
  <p>Given an object to unmarshal that has been created using a marshal method such as</p>
  
  <pre><code>     marshaller.marshal( new JAXBElement(
                          new QName("urn:somenamespace","DifferentNameMessage"), 
                          OriginalMessageType.class, 
                          originalMsg), 
                     result);
  </code></pre>
  
  <p>(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".)</p>
  
  <p>I would normally use a method of unmarshalling such as:</p>
  
  <pre><code>     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);
  </code></pre>
  
  <p>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.</p>
  
  <p>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?</p>