在Java中将树映射与SOAP一起使用

在Java中将树映射与SOAP一起使用,java,serialization,soap,treemap,Java,Serialization,Soap,Treemap,我试图在SOAP服务的方法中返回树映射,获得以下异常: Exception in thread "main" javax.xml.ws.WebServiceException: Unable to create JAXBContext at com.sun.xml.internal.ws.model.AbstractSEIModelImpl.createJAXBContext(Unknown Source) at com.sun.xml.internal.ws.model.Abs

我试图在SOAP服务的方法中返回树映射,获得以下异常:

Exception in thread "main" javax.xml.ws.WebServiceException: Unable to create JAXBContext
    at com.sun.xml.internal.ws.model.AbstractSEIModelImpl.createJAXBContext(Unknown Source)
    at com.sun.xml.internal.ws.model.AbstractSEIModelImpl.postProcess(Unknown Source)
    at com.sun.xml.internal.ws.model.RuntimeModeler.buildRuntimeModel(Unknown Source)
    at com.sun.xml.internal.ws.server.EndpointFactory.createSEIModel(Unknown Source)
    at com.sun.xml.internal.ws.server.EndpointFactory.createEndpoint(Unknown Source)
    at com.sun.xml.internal.ws.api.server.WSEndpoint.create(Unknown Source)
    at com.sun.xml.internal.ws.transport.http.server.EndpointImpl.createEndpoint(Unknown Source)
    at com.sun.xml.internal.ws.transport.http.server.EndpointImpl.publish(Unknown Source)
    at com.sun.xml.internal.ws.spi.ProviderImpl.createAndPublishEndpoint(Unknown Source)
    at javax.xml.ws.Endpoint.publish(Unknown Source)
    at webservice.soap.ServicePublisher.main(ServicePublisher.java:15)
Caused by: java.security.PrivilegedActionException: com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
java.util.List is an interface, and JAXB can't handle interfaces.
    this problem is related to the following location:
        at java.util.List
        at public java.util.TreeMap dictionary.jaxws.GetWordsBegginingWithResponse._return
        at dictionary.jaxws.GetWordsBegginingWithResponse

    at java.security.AccessController.doPrivileged(Native Method)
    ... 11 more
Caused by: com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
java.util.List is an interface, and JAXB can't handle interfaces.
    this problem is related to the following location:
        at java.util.List
        at public java.util.TreeMap dictionary.jaxws.GetWordsBegginingWithResponse._return
        at dictionary.jaxws.GetWordsBegginingWithResponse

    at com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException$Builder.check(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(Unknown Source)
    at com.sun.xml.internal.bind.v2.ContextFactory.createContext(Unknown Source)
    at com.sun.xml.internal.bind.api.JAXBRIContext.newInstance(Unknown Source)
    at com.sun.xml.internal.ws.developer.JAXBContextFactory$1.createJAXBContext(Unknown Source)
    at com.sun.xml.internal.ws.model.AbstractSEIModelImpl$1.run(Unknown Source)
    at com.sun.xml.internal.ws.model.AbstractSEIModelImpl$1.run(Unknown Source)
    ... 12 more

为什么它试图序列化一个列表?我可以让它与任何其他SortedMap一起工作吗?

正如@PaulVargas在评论中指出的,JAX-B不直接支持TreeMap


我解决了这个问题,创建了我的TreeMapSerializer来适应这个答案

SortedMap和其他Map实现都不受JAX-B的直接支持。@PaulVargas SortedMap是一个接口,我想你的意思是TreeMap有没有办法手动添加对它们的支持?你能给我们看看你的代码吗?@Santiago我认为这不相关,所以我并没有把它添加到问题中,但这里有一个隐含的片段:它试图序列化一个列表,因为TreeMap的构造函数中有一个列表。