title: How to create java object from 'anyType' returned from service using JAXB?
body: <p>A web service is returning an object defined by the WSDL to be:</p>
  
  <pre><code>&lt;s:complexType mixed="true"&gt;&lt;s:sequence&gt;&lt;s:any/&gt;&lt;/s:sequence&gt;&lt;/s:complexType&gt;
  </code></pre>
  
  <p>When I print out this object's class info, it comes up as:</p>
  
  <pre><code>class com.sun.org.apache.xerces.internal.dom.ElementNSImpl
  </code></pre>
  
  <p>But I need to unmarshall this object as an object of the following class:</p>
  
  <pre><code>@XmlAccessorType(XmlAccessType.FIELD) 
  @XmlType(name = "", propOrder = {
          "info",
          "availability",
          "rateDetails",
          "reservation",
          "cancellation",
          "error" }) 
  @XmlRootElement(name = "ArnResponse") 
  public class ArnResponse { }
  </code></pre>
  
  <p>I know the response is correct, since I know how to marshall this object's XML:</p>
  
  <pre><code>Marshaller m = jc.createMarshaller();
  m.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE );
  m.marshal(rootResponse, System.out);
  </code></pre>
  
  <p>Which prints out:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
  &lt;ns2:SubmitRequestDocResponse xmlns:ns2="http://tripauthority.com/hotel"&gt;
      &lt;ns2:SubmitRequestDocResult&gt;
          &lt;!-- below is the object I'm trying to unmarshall --&gt;
          &lt;ArnResponse&gt;
              &lt;Info /&gt;
              &lt;Availability&gt;
                  &lt;!-- etc--&gt; 
               &lt;/Availability&gt;
          &lt;/ArnResponse&gt;
      &lt;/ns2:SubmitRequestDocResult&gt;
  &lt;/ns2:SubmitRequestDocResponse&gt;
  </code></pre>
  
  <p>How can I turn the <code>ElementNSImpl</code> object I'm seeing into the <code>ArnResponse</code> object I know it represents?</p>
  
  <p>Additionally, I'm running on AppEngine, where file access is restricted.</p>
  
  <p>Thanks for any help</p>
  
  <p><strong>Update</strong>:</p>
  
  <p>I've added the <code>@XmlAnyElement(lax=true)</code> annotation, like so:</p>
  
  <pre><code>  @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "", propOrder = {
        "content"
    })
    @XmlSeeAlso(ArnResponse.class)
    public static class SubmitRequestDocResult {
  
      @XmlMixed
      @XmlAnyElement(lax = true)
      protected List&lt;Object&gt; content;
  </code></pre>
  
  <p>But it doesn't make any difference. </p>
  
  <p>Is this something to do with the fact that the content is a <code>List</code>?</p>
  
  <p>Here's the code where I'm trying to access the content after getting it back from the server:</p>
  
  <pre><code>List list = rootResponse.getSubmitRequestDocResult().getContent();
  
  for (Object o : list) {
    ArnResponse response = (ArnResponse) o;
    System.out.println(response);
  }
  </code></pre>
  
  <p>Which has the output:</p>
  
  <blockquote>
    <p>Jan 31, 2012 10:04:14 AM
    com.districthp.core.server.ws.alliance.AllianceApi getRates SEVERE:
    com.sun.org.apache.xerces.internal.dom.ElementNSImpl cannot be cast to
    com.districthp.core.server.ws.alliance.response.ArnResponse</p>
  </blockquote>
  
  <p><strong>Answer:</strong></p>
  
  <p>axtavt's answer did the trick.  This worked:</p>
  
  <pre><code>Object content = ((List)result.getContent()).get(0);
  JAXBContext context = JAXBContext.newInstance(ArnResponse.class);
  Unmarshaller um = context.createUnmarshaller();
  ArnResponse response = (ArnResponse)um.unmarshal((Node)content);
  System.out.println("response: " + response);
  </code></pre>