Could anyone tell me what I am doing wrong.
Trying to marshall a complex map (Map<String,List<String>>)
MyBean.java
private Map<String,List<String>> valueMapList=null;
@XmlJavaTypeAdapter(MyHashMapAdapter.class)
@XmlElement
public Map<String, List<String>> getValueMapList() {
return valueMapList;
}
public void setValueMapList(Map<String, List<String>> valueMapList) {
this.valueMapList = valueMapList;
}
MyHashMapAdapter.java
public class MyHashMapAdapter extends XmlAdapter<String[], List<String>> {
public List<String> unmarshal( String[] value ) {
List<String> r = new ArrayList<String>();
for( String s : value )
r.add(s);
return r;
}
public String[] unmarshal( List<String> value ) {
return value.toArray(new String[value.size()]);
}
@Override
public String[] marshal(List<String> arg0) throws Exception {
String[] s = (String[]) arg0.toArray();
return s;
}
}
This is my error
java.io.IOException: Error marshalling JAXB object of type "class
com.MyBean".
at
com.sun.jersey.core.provider.jaxb.AbstractRootElementProvider.writeTo(AbstractRootElementProvider.java:145)
at
com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:254)
at
com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:578)
at
com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:502)
at
com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:493)
Truncated. see log file for complete stacktrace
com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 3 counts of
IllegalAnnotationExceptions
Adapter com.MyHashMapAdapter is not applicable to the field type
java.util.Map<java.lang.String, java.util.List<java.lang.String>>.
this problem is related to the following location:
at @javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter(type=class
javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter$DEFAULT, value=class
com.MyHashMapAdapter)
at public java.util.Map com.MyBean.getValueMapList()
at com.MyBean
java.util.Map is an interface, and JAXB can't handle interfaces.
this problem is related to the following location:
at java.util.Map
at public java.util.Map com.MyBean.getValueMapList()
at com.MyBean
java.util.Map does not have a no-arg default constructor.
this problem is related to the following location:
at java.util.Map
at public java.util.Map com.MyBean.getValueMapList()
at com.MyBean
at
com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:102)
at
com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:447)
at
com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:288)
at
com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1111)
at
com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:154)
Truncated. see log file for complete stacktrace
--
View this message in context: http://www.nabble.com/Error-marshalling-JAXB-object-tp24852727p24852727.html
Sent from the java.net - jaxb users mailing list archive at Nabble.com.