A simple^W dumb Map wrapper to use with JAXB
I sometimes need to use java.util.Map objects in WebServices. As I’m building all my WebServices with the JAX-WS RI (using the Metro bundle). The block responsible for XML (un)marshalling of POJO, named JAXB, does not allows to directly use Maps as a soap operation parameter. For this purpose I’ve written the following simple class that allows me to wrap Maps in a POJO that JAXB is able to (un)marshall :
public class JAXBMapWrapper<KT, VT> {
private Map<KT, VT> wrappedMap;
public JAXBMapWrapper() {
wrappedMap = new HashMap<KT, VT>();
}
public Map<KT, VT> getWrappedMap() {
return wrappedMap;
}
public void setWrappedMap(final Map<KT, VT> givenMap) {
wrappedMap = givenMap;
}
}
ATTENTION : I posted this some days ago and removed the post after understanding that this is simpler on the service side but that the client side gets cumbersome generated classes.. but google cache indexed the post in less than half a day.
Just don’t use this !
If you need to transmit Maps over JAX-WS webservices, do it the XmlAdapter way as advertised in the official Unofficial JAXB Guide instead.