title: How to map an Hashmap to key-value-attributes in XML using xstream
body: <p>I have the following entity:</p>
  
  <pre><code>@XStreamAlias("entity")
  public class MapTestEntity {
  
      @XStreamAsAttribute
      public Map&lt;String, String&gt; myMap = new HashMap&lt;&gt;();
  
      @XStreamAsAttribute
      public String myText;
  }
  </code></pre>
  
  <p>I use it with xstream like:</p>
  
  <pre><code>MapTestEntity e = new MapTestEntity();
  e.myText = "Foo";
  e.myMap.put("firstname", "homer");
  e.myMap.put("lastname", "simpson");
  
  XStream xstream = new XStream(new PureJavaReflectionProvider());
  xstream.processAnnotations(MapTestEntity.class);
  System.out.println(xstream.toXML(e));
  </code></pre>
  
  <p>and get the following xml:</p>
  
  <pre><code>&lt;entity myText="Foo"&gt;
    &lt;myMap&gt;
      &lt;entry&gt;
        &lt;string&gt;lastname&lt;/string&gt;
        &lt;string&gt;simpson&lt;/string&gt;
      &lt;/entry&gt;
      &lt;entry&gt;
        &lt;string&gt;firstname&lt;/string&gt;
        &lt;string&gt;homer&lt;/string&gt;
      &lt;/entry&gt;
    &lt;/myMap&gt;
  &lt;/entity&gt;
  </code></pre>
  
  <p>But I need to map the <code>HashMap</code> to attributes in xml like:</p>
  
  <pre><code>&lt;entity myText="Foo" lastname="simpson" firstname="homer" /&gt;
  </code></pre>
  
  <p>How can I do that with XStream? Can I use a custom converter or mapper or something like that? TIA!!</p>
  
  <p>(Of course my code needs to be ensure that are no duplicates in xml attributes.)</p>