aspose file tools*
The moose likes Web Services and the fly likes JAXB mapping of HashMap Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "JAXB mapping of HashMap" Watch "JAXB mapping of HashMap" New topic
Author

JAXB mapping of HashMap

Bharath Chinnadurai Maharajan
Greenhorn

Joined: Dec 22, 2004
Posts: 26
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

Joined: Aug 19, 2005
Posts: 2922
    
    5
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
 
subject: JAXB mapping of HashMap