users@jaxb.java.net

Re: Is java.util.Map supported in JAXB 2.0

From: raags <apparna_at_gmail.com>
Date: Mon, 31 Mar 2008 19:37:21 -0700 (PDT)

You are right. I tried to use an adapter and that seems to fail as well.
I'm using JBoss 4.2 w/ JBossWS 1.2.1 to deploy this....

@WebMethod
@XmlJavaTypeAdapter(MapAdapter.class)
public Map<String, Boolean> getMap()
{
Map<String, Boolean> map = new HashMap<String, Boolean>();
return map;

}

MapAdapter.java
public class MapAdapter extends XmlAdapter<MapElements[]>
{

@Override
public MapElements[] marshal(Map<String, Boolean> arg0) throws Exception
{
return arg0.values().toArray(new MapElements[arg0.size()]);
}

@Override
public Map<String, Boolean> unmarshal(MapElements[] arg0) throws Exception {
Map<String,Boolean> r = new HashMap<String,Boolean>();
for( MapElements mapelement : arg0)
r.put(mapelement.key, mapelement.value);
return r;

}
}


public class MapElements
{
@XmlElement
public String key;
@XmlElement
public Boolean value;

public MapElements() {} // Required for marshalling to work

public MapElements(String key, Boolean value) {
this.key = key;
this.value = value;
}


}

What am I doing wrong here?


-- 
View this message in context: http://www.nabble.com/Is-java.util.Map-supported-in-JAXB-2.0-tp16389809p16408221.html
Sent from the java.net - jaxb users mailing list archive at Nabble.com.