title: Using JAXB to unmarshal a hash map from a list
body: <p>I have an xml of this structure (Key value pairs of items):
  </p>
  
  <pre><code>&lt;root&gt;
    &lt;item value="dada" key="dad" /&gt;
    &lt;item value="mama" key="mum" /&gt;
    &lt;others&gt;
      &lt;os&gt;asdad&lt;/os&gt;
    &lt;/others&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>I want to map the item elements to a HashMap, the string is Item.key</p>
  
  <p>I wrote an adapter that unmarshals a list from the xml and marshals a map to a list.
  Problem is, JAXB gets the list emtpy when unmarshal-ing and only writes one item when marshal-ing to xml.</p>
  
  <p>Here are the corresponding classes:</p>
  
  <p>Root.java
  </p>
  
  <pre><code>@XmlRootElement(name = "root")
  public class Root
  {
      @XmlJavaTypeAdapter(ItemMapAdapter.class)
      @XmlElement(name = "item")
      public HashMap&lt;String, Item&gt; getContent()
      {
          return content;
      }
  
      public void setContent(HashMap&lt;String, Item&gt; content)
      {
          this.content = content;
      }
  
      private HashMap&lt;String, Item&gt; content;
  }
  </code></pre>
  
  <p>ItemMapAdapter.java
  </p>
  
  <pre><code>public final class ItemMapAdapter extends XmlAdapter&lt;HashMap&lt;String, Item&gt;, LinkedList&lt;Item&gt;&gt;
  {
      @Override
      public HashMap&lt;String, Item&gt; marshal(LinkedList&lt;Item&gt; v)
      {
           //the list here is empty.
           //returns a map&lt;Item.key, Item&gt;
      }
  
      @Override
      public LinkedList&lt;Item&gt; unmarshal(HashMap&lt;String, Item&gt; v){}
  }
  </code></pre>
  
  <p>Anyone has any insights?
  probably am missing something..
  <strong>Thanks!</strong></p>