title: Dynamic XML attributes with JAXB
body: <p>I have an <code>XML</code> file that I am trying to unmarshall to java object using <code>JAXB</code></p>
  
  <pre><code>&lt;root&gt;
      &lt;object att1="orgA" att2="orgA" id="6" name=""&gt;
          ...
      &lt;/object&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p><code>Java</code> class:</p>
  
  <pre><code>@AllArgsConstructor
  @NoArgsConstructor
  @ToString
  @Setter
  @XmlRootElement(name="object")
  public class ObjectElement implements Serializable {
  
  @XmlAttribute
  private int id;
  
  @XmlAttribute
  private String attr1;
  
  @XmlAttribute
  private String attr2;
  
  @XmlAttribute
  private String name;
  
  }
  </code></pre>
  
  <p>Question: attributes of xml element <code>object</code> may change dynamically. So keys of the attributes may be dynamic so there is no way of putting them as <code>XmlAttributes</code> in class. Is there a way to define some sort of <code>HashMap</code> that reads all keys of <code>object</code> and corresponding values? For instance new object could have totally different attributes like this;</p>
  
  <pre><code>&lt;object att5="some" att7="other" id="6" name="value"&gt;
      ...
  &lt;/object&gt;
  </code></pre>