Dealing with passing HashMap<> back and forth with JAX-WS has always been a known complaint as I recall. The solution of using ArrayList<> is, in fact, something I have seen developers use numerous times in our own environment. Though not ideal, it is a workaround.
This search alone will show numerous items on this topic as it is a rather popular question: https://www.google.com/search?q=jax-ws+return+hashmap&oq=JAX-WS+AND+HASHMAP There is also a passing mention of it here in the CXF docs: https://cxf.apache.org/docs/a-simple-jax-ws-service.html *Mark* On Tue, Apr 1, 2014 at 12:29 PM, Al Eridani <[email protected]> wrote: > Thank you, Mark, for your reply. > > > However with > > *java.lang.Object*- what XML Schema type could that correspond to in > > order to get > > serialized/deserialized to by JAXB? > > Well, I've found out that JAXB is able to do it, anyway. > > The error message reminded me that in the past there had been problems > with serialization of interfaces. So, in desperation, I changed the Map<,> > to HashMap<,> and afterwards the error message changed to > > class java.util.ArrayList nor any of its super class is known to this > context. > > So, I changed the List<> to ArrayList<> in the signature of the web service > method and now the web service works again. > > Of course, this "solution" is extremely ugly, so if somebody has some > suggestions on how to fix the problem without resorting to signatures with > concrete classes, please share your insights. > > Thanks! > > > > On Mon, Mar 31, 2014 at 2:22 PM, Mark Streit <[email protected]> wrote: > > > I am just taking a guess here, but Map<String, String> has elements which > > are definable by XML Schema types as *xsd:String*, by default as these > > represent typical *java.lang.String* types. However with > > *java.lang.Object*- what XML Schema type could that correspond to in > > order to get > > serialized/deserialized to by JAXB? > > > > As stated, I am just guessing but that is the first thing that "jumps" > out. > > I'm sure the CXF gurus (Daniel, Sergey, etc) would know more than me. > > > > Mark > > > > > > > > > > On Mon, Mar 31, 2014 at 8:11 PM, Al Eridani <[email protected]> > wrote: > > > > > I have a CXF 2.6.2 web service that works fine returning a List of > custom > > > result objects, each of which contains (among other things) a member of > > > type Map<String, String>. Like this: > > > > > > public class Result { > > > > > > ... > > > > > > private Map<String, String> definition; > > > > > > ... > > > > > > public Map<String, String> getDefinition() { > > > return definition; > > > } > > > public void setDefinition(Map<String, String> definition) { > > > this.definition = definition; > > > } > > > > > > ... > > > } > > > > > > But, if I change the type of "definition" above to Map<String, Object> > > (and > > > the accessors and other dependent code, of course) it fails with the > > > exception below. > > > > > > Any ideas? > > > > > > javax.xml.bind.JAXBException: class java.util.HashMap nor any of its > > super > > > class is known to this context.] > > > at > > > > com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:326) > > > at > > > > > > com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:251) > > > at > > > > > > > > > javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:75) > > > at > > > > > > > > > org.apache.cxf.jaxb.JAXBEncoderDecoder.writeObject(JAXBEncoderDecoder.java:554) > > > at > > > > > > > > > org.apache.cxf.jaxb.JAXBEncoderDecoder.marshall(JAXBEncoderDecoder.java:236) > > > at org.apache.cxf.jaxb.io.DataWriterImpl.write(DataWriterImpl.java:168) > > > at > > > > > > > > > org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor.writeParts(AbstractOutDatabindingInterceptor.java:110) > > > at > > > > > > > > > org.apache.cxf.interceptor.BareOutInterceptor.handleMessage(BareOutInterceptor.java:68) > > > at > > > > > > > > > org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:262) > > > at > > > > > > > > > org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(OutgoingChainInterceptor.java:77) > > > at > > > > > > > > > org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:262) > > > at > > > > > > > > > org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121) > > > at > > > > > > > > > org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:211) > > > at > > > > > > > > > org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:213) > > > at > > > > > > > > > org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:193) > > > at > > > > > > > > > org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:130) > > > at > > > > > > > > > org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:221) > > > at > > > > > > > > > org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:141) > > > at javax.servlet.http.HttpServlet.service(HttpServlet.java:616) > > > at > > > > > > > > > org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:197) > > > at > org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:427) > > > at > > > > > > > > > org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:832) > > > at > > > > > > > > > com.planetj.servlet.filter.compression.CompressingFilter.doFilter(CompressingFilter.java:222) > > > at > > > > > > > > > org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:823) > > > at > > > > > > > > > org.mypkg.servlet.BaseServletManager$CompressingFilterWrapper.doFilter(BaseServletManager.java:780) > > > at > > > > > > > > > org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:823) > > > at > > > > > > > > > org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:473) > > > at > > org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:567) > > > at org.mortbay.http.HttpContext.handle(HttpContext.java:1565) > > > at org.mortbay.http.HttpContext.handle(HttpContext.java:1517) > > > at org.mortbay.http.HttpServer.service(HttpServer.java:954) > > > at org.mortbay.http.HttpConnection.service(HttpConnection.java:820) > > > at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:987) > > > at org.mortbay.http.HttpConnection.handle(HttpConnection.java:837) > > > at > > > > org.mortbay.http.SocketListener.handleConnection(SocketListener.java:244) > > > at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:357) > > > at org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:534) > > > Caused by: javax.xml.bind.JAXBException: class java.util.HashMap nor > any > > of > > > its super class is known to this context. > > > at > > > > > > > > > com.sun.xml.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:247) > > > at > > > > > > > > > com.sun.xml.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:262) > > > at > > > > > > > > > com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:653) > > > at > > > > > > > > > com.sun.xml.bind.v2.runtime.property.SingleMapNodeProperty.serializeBody(SingleMapNodeProperty.java:275) > > > at > > > > > > > > > com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:358) > > > at > > > > > > > > > com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:696) > > > at > > > > > > > > > com.sun.xml.bind.v2.runtime.property.ArrayElementNodeProperty.serializeItem(ArrayElementNodeProperty.java:69) > > > at > > > > > > > > > com.sun.xml.bind.v2.runtime.property.ArrayElementProperty.serializeListBody(ArrayElementProperty.java:172) > > > at > > > > > > > > > com.sun.xml.bind.v2.runtime.property.ArrayERProperty.serializeBody(ArrayERProperty.java:159) > > > at > > > > > > > > > com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:358) > > > at > > > > > > > > > com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:696) > > > at > > > > > > > > > com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(ElementBeanInfoImpl.java:156) > > > at > > > > > > > > > com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(ElementBeanInfoImpl.java:131) > > > at > > > > > > > > > com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeBody(ElementBeanInfoImpl.java:333) > > > at > > > > > > > > > com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(ElementBeanInfoImpl.java:340) > > > at > > > > > > > > > com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(ElementBeanInfoImpl.java:76) > > > at > > > > > > > > > com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:494) > > > at > > > > com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:323) > > > ... 36 more > > > Caused by: javax.xml.bind.JAXBException: class java.util.HashMap nor > any > > of > > > its super class is known to this context. > > > at > > > > > > > > > com.sun.xml.bind.v2.runtime.JAXBContextImpl.getBeanInfo(JAXBContextImpl.java:588) > > > at > > > > > > > > > com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:648) > > > ... 51 more > > > > > >
