2

f.e. I have an xml:

<a>
  <b id="1">abc</b>
  <b id="22">bzzz</b>
</a>

I want to map it onto
Map < Integer, String >

is it possible with jaxb? If yes - how?

Thank you.

denys
  • 2,437
  • 6
  • 31
  • 55
  • This question was asked so many times: [Is it possible to use JAXB to map from schema to a java.util.Map?](http://stackoverflow.com/questions/1881712), [XMLAdapter for HashMap](http://stackoverflow.com/questions/4975068), [Problems marshalling a map in Jaxb](http://stackoverflow.com/questions/7793283), [Custom Map XmlAdapter](http://stackoverflow.com/questions/9034781). – dma_k Feb 18 '12 at 12:53

1 Answers1

2

Read documentation for XmlAdapter. It gives you what you want.

forty-two
  • 12,204
  • 2
  • 26
  • 36
  • +1 - Here is another link you may find useful: http://blog.bdoughan.com/2010/07/xmladapter-jaxbs-secret-weapon.html – bdoughan Feb 14 '12 at 11:50
  • An operational example for generics is also available here (personal blog post): http://tshikatshikaaa.blogspot.nl/2012/08/jaxb-annotation-summary-advanced-topics_9.html – Jérôme Verstrynge Aug 08 '12 at 23:23