title: JAXB : How to remove wrapping tag when using Map
body: <p>I use <code>@XmlJavaTypeAdapter</code> to transform <code>Map&lt;Key, Value&gt;</code> objects into <code>List&lt;Value&gt;</code> when marshalling and the other way round when un-marshalling </p>
  
  <p>Then the XML I obtain :</p>
  
  <pre><code>&lt;map&gt;
      &lt;value&gt;VALUE1&lt;/value&gt;
  ...
  &lt;/map&gt;
  </code></pre>
  
  <p><strong>My question is</strong> : how can I get rid of the surrounding  tag in order to obtain</p>
  
  <pre><code>&lt;value&gt;VALUE1&lt;/value&gt;
  </code></pre>
  
  <p><strong>Bean Class</strong></p>
  
  <pre><code>@XmlAccessorType(XmlAccessType.FIELD)
  public class Data implements Serializable {
  
    /**
     * Constant for data value default name
     */
    public static final String DATA_VALUE_DEFAULT_NAME = "result";
  
    /**
     * Serial version UID
     */
    private static final long serialVersionUID = 7387937212735185585L;
  
    /**
     * key
     */
    @XmlAttribute
    private String key;
  
    /**
     * name
     */
    @XmlAttribute
    private String name;
  
    /**
     * Map of data
     */
    @XmlJavaTypeAdapter(MapDataAdapter.class)
    private Map&lt;String, Data&gt; dataMap;
  
    /**
     * Constructor
     */
    public Data() {
  
    }
  }
  </code></pre>
  
  <p><strong>Adapter</strong></p>
  
  <pre><code>public class MapDataAdapter 
    extends XmlAdapter&lt;MapDataAdapter.AdaptedDataMap,
                       Map&lt;String, Data&gt;&gt; {
  
    /**
     * Adapted map
     */
    public static class AdaptedDataMap {
  
      /**
       * List of entry
       */
      @XmlElement(name = "data", required = true)
      protected List&lt;Data&gt; entry = new ArrayList&lt;&gt;();
    }
  
    /**
     * {@inheritDoc}
     */
    @Override
    public Map&lt;String, Data&gt; unmarshal(
      AdaptedDataMap adaptedMap) throws Exception {
      if (adaptedMap == null) {
       return null;
      }
      Map&lt;String, Data&gt; map = new HashMap&lt;&gt;(adaptedMap.entry.size());
      for (Data entry : adaptedMap.entry) {
        map.put(entry.getKey(), entry);
      }
      return map;
    }
  
    /**
     * {@inheritDoc}
     */
    @Override
    public AdaptedDataMap marshal(
        Map&lt;String, Data&gt; map) throws Exception {
      if (map == null) {
        return null;
      }
      AdaptedDataMap adaptedMap = new AdaptedDataMap();
      for (Entry&lt;String, Data&gt; mapEntry : map.entrySet()) {
        adaptedMap.entry.add(mapEntry.getValue());
      }
      return adaptedMap;
    }
  }
  </code></pre>
  
  <p><strong>XML Output</strong></p>
  
  <pre><code>&lt;data key="12" name="TEST1"&gt;
      &lt;dataMap&gt;
          &lt;data key="text" name="TEST2"&gt;
              &lt;dataMap&gt;
                  &lt;data key="azerty" name="TEST3"&gt;
                  &lt;/data&gt;
              &lt;/dataMap&gt;
          &lt;/data&gt;
      &lt;/dataMap&gt;
  &lt;/data&gt;
  </code></pre>
  
  <p><strong>What I need</strong> </p>
  
  <pre><code>&lt;data key="12" name="TEST1"&gt;
      &lt;data key="text" name="TEST2"&gt;
              &lt;data key="azerty" name="TEST3"&gt;
              &lt;/data&gt;
      &lt;/data&gt;
  &lt;/data&gt;
  </code></pre>