title: JAXB XmlJavaAdapter working with Interface with @XmlAnyElement not with @XmlElement
body: <p>I have an implementation of XmlAdapter class as follows:</p>
  
  <pre><code>public class XMLSimpleElementAdapter extends XmlAdapter&lt;Element, String&gt; {
  
  protected static final DocumentImpl doc=new DocumentImpl(true);
  
  protected String elementName;
  protected String nameSpace;
  
  public XMLSimpleElementAdapter() {
      this("Description","https://www.proviseconsulting.com/ProcessDataModelDefinition");
  }
  
  public XMLSimpleElementAdapter(String elementName, String nameSpace) {
  
      this.elementName=elementName;
      this.nameSpace=nameSpace;
  
  }//constructor closing
  
  @Override
  public Element marshal(String value) throws Exception {
  
      System.out.println("XMLSimpleElementAdapter -- marshal called");
  
      Element element=doc.createElement(elementName);
      element.setAttribute("xmlns", nameSpace);
  
      if(value!=null) {
  
          Node textValue=doc.createTextNode(value);
          element.appendChild(textValue);
  
      }//if closing
  
      return (Element)element;
  
  }//marshal closing
  
  @Override
  public String unmarshal(Element element) throws Exception {
  
      System.out.println("XMLSimpleElementAdapter -- unmarshal called");
  
      String value="Some hard coded value";
  
      try {
      System.out.println("Element = "+element.getParentNode());
      }catch(Exception e) {e.printStackTrace();}
      Node textValue=element.getFirstChild();
      if(textValue!=null) {value=textValue.getNodeValue();}
  
      return value;
  
  }//unmarshal closing
    }//class closing
  </code></pre>
  
  <p>I am using the adapter on an attribute of a class:</p>
  
  <pre><code>@XmlAnyElement
  //@XmlElement(name="Description",namespace="https://www.proviseconsulting.com/TriggerConfig")
  @XmlJavaTypeAdapter(value = XMLSimpleElementAdapter.class)
  protected String description;
  </code></pre>
  
  <p>Where the XML is: <code>&lt;Description&gt;This is the description of the configuration.&lt;/Description&gt;</code></p>
  
  <p>It works perfectly and I get the value. However, if I use the commented '@XmlElement' annotation instead of @XmlAnyElement, I get the following error:</p>
  
  <pre><code>    Exception in thread "main"   com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
  org.w3c.dom.Element is an interface, and JAXB can't handle interfaces.
      this problem is related to the following location:
          at org.w3c.dom.Element
          at protected java.lang.String com.provise.wfm.trigger.config.TriggerConfigImpl.description
          at com.provise.wfm.trigger.config.TriggerConfigImpl
  </code></pre>
  
  <p>Am I missing something, JAXB can handle org.W3c.dom.Element with @XmlAnyType and not with @XmlElement type??</p>
  
  <p>I am using JAXB implementation from Sun/Oracle with JDK 12 (AdoptOpenJDK with J9)</p>