File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JAXB mapping of HashMap

 
Bharath Chinnadurai Maharajan
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
XSD types does not include a HashMap as it includes a List. Is there a workaround in which i can use a HashMap the same way is use a List.


I have a need to send a HasMap of some data over the wire. Is there a workaround by which i can achieve this.

Thanks.
Bharath
 
Peer Reynders
Bartender
Posts: 2939
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
XML (Schema) has no idea what a HashMap is. However from a data perspective it is nothing but a list of pairs where each pair has a unique key and an associated value (in Java the pair is java.util.Map.Entry). So that data can easily be structured like:



This internal structure is exposed as a Set<Map.Entry<K,V>> through java.util.HashMap.entrySet(). java.util.Set.toArray() can then turn it into a array of Map.Entry<K,V> for which it shouldn't be too difficult to set up a mapping.

Of course you could simply put the Hashmap inside of a container class as JAXB can handle a HashMap as a return value from a bean - it just can't deal with it as a top level object. Mapping your favorite class (HashMap)

XML layout and in-memory data layout (XmlJavaTypeAdapter)
[ December 10, 2008: Message edited by: Peer Reynders ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic