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.
posted 7 years ago
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)