title: JAXB: how to marshall map into <key>value</key>
body: <p>The question is about JAXB Map marshalling - there is plenty of examples on how to marhsall a Map into a structure like follows:</p>
  
  <pre><code>&lt;map&gt;
    &lt;entry&gt;
      &lt;key&gt; KEY &lt;/key&gt;
      &lt;value&gt; VALUE &lt;/value&gt;
    &lt;/entry&gt;
    &lt;entry&gt;
      &lt;key&gt; KEY2 &lt;/key&gt;
      &lt;value&gt; VALUE2 &lt;/value&gt;
    &lt;/entry&gt;
    &lt;entry&gt;
    ...
  &lt;/map&gt;
  </code></pre>
  
  <p>In fact, this is natively supported by JAXB. What I need, however, is the XML where key is the element name, and value is its content:</p>
  
  <pre><code>&lt;map&gt;
    &lt;key&gt; VALUE &lt;/key&gt;
    &lt;key2&gt; VALUE2 &lt;/key2&gt;
   ...
  &lt;/map&gt;
  </code></pre>
  
  <p>I didn't succeed implementing my Map adapter the way it is recommended by JAXB developers (<a href="https://jaxb.dev.java.net/guide/Mapping_your_favorite_class.html" rel="noreferrer">https://jaxb.dev.java.net/guide/Mapping_your_favorite_class.html</a>), as I need, he - dynamic attribute name :) </p>
  
  <p>Is there any solution for that?</p>
  
  <p>P.S. Currently I have to create a dedicated container class for each typical set of key-value pairs I want to marshall to XML - it works, but I have to create way too many of these helper containers.</p>