[英]Use TreeMap with SOAP in Java
I am trying to return a TreeMap in a method in my SOAP service, obtaining the following exception: 我试图在我的SOAP服务的方法中返回TreeMap,获得以下异常:
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
Why is it trying to serialize a List
? 为什么要尝试序列化List
? Can I make it work with any other SortedMap
? 我可以使其与其他SortedMap
吗?
As pointed out by @PaulVargas in the comments, TreeMap
is not directly supported by JAX-B. 正如@PaulVargas在评论中指出的那样,JAX-B不直接支持TreeMap
。
I resolved this issue creating my TreeMapSerializer adapting this answer JAXB: How to suppress surrounding XmlElement when using XmlJavaTypeAdapter? 我已解决此问题,并创建了我的TreeMapSerializer来适应此答案JAXB:使用XmlJavaTypeAdapter时如何抑制周围的XmlElement?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.