The question is about JAXB Map marshalling – there is plenty of examples on how to marhsall a Map into a structure like follows:
<map>
<entry>
<key> KEY </key>
<value> VALUE </value>
</entry>
<entry>
<key> KEY2 </key>
<value> VALUE2 </value>
</entry>
<entry>
...
</map>
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:
<map>
<key> VALUE </key>
<key2> VALUE2 </key2>
...
</map>
I didn’t succeed implementing my Map adapter the way it is recommended by JAXB developers (https://jaxb.dev.java.net/guide/Mapping_your_favorite_class.html), as I need, he – dynamic attribute name 🙂
Is there any solution for that?
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.
the code provided didn’t work for me.
I found another way to Map :
MapElements :
MapAdapter :
The rootElement :
I found the code in this website :
http://www.developpez.net/forums/d972324/java/general-java/xml/hashmap-jaxb/