Java Web 服务/JAXB - 抽象超类
我有一个包含 JAXB 带注释的类和抽象超类的包。我想在 Web 服务接口中使用这个超类,所以我 可以将任何子类作为参数传递。当我这样做时,会抛出异常:
javax.xml.ws.WebServiceException: javax.xml.bind.UnmarshalException
- with linked exception:
[javax.xml.bind.UnmarshalException: Unable to create an instance of xxx.yyy.ZZZ
- with linked exception:
[java.lang.InstantiationException]]
可以手动编组/解组&将参数作为字符串传递,但我想避免它。有什么想法如何去做吗?
I have a package with JAXB annotated classes with an abstract superclass. I want to use this superclass in web service interface, so I
can pass any of subclasses as a parameter. When I do it, an exception is thrown:
javax.xml.ws.WebServiceException: javax.xml.bind.UnmarshalException
- with linked exception:
[javax.xml.bind.UnmarshalException: Unable to create an instance of xxx.yyy.ZZZ
- with linked exception:
[java.lang.InstantiationException]]
It is possible to manually marshall/unmarshall & pass parameter as a string, but I would like to avoid it. Any ideas how to do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您在Web服务请求中指定了具体的实现吗?这对我来说效果很好:
抽象基类:
实现类:
Web 服务方法:
请求:
Have you specified the concrete implementation in your web service request? This works fine for me:
Abstract base class:
Implementation class:
Web service method:
Request:
我今天正在解决同样的问题。
我发现 EclipseLink MOXy JAXB 实现可以工作,但没有单独的 jar 或 maven 模块可用(它只是整个 eclipselink.jar,它很大)
最后我尝试了最新的 JAXB 版本(2.2.2),令人惊讶的是它运行得很好。
行家配置:
I was solving the same issue today.
I found EclipseLink MOXy JAXB implementation as working, but there is no separate jar or maven module available (it is only as whole eclipselink.jar, which is huge)
Finally I tried the latest JAXB version (2.2.2) and surprisingly it worked well.
maven config:
我有一个类似的问题,上面的评论没有解决。从 JAXB 解组期间的实例化异常链接的博客文章(抽象基类,带有@XmlSeeAlso 具体子类) 对我理解我真正在做什么非常有帮助。
I had a similar Problem, which the comments above didn't solve. The Blogsposts linked from InstantiationException during JAXB Unmarshalling (abstract base class, with @XmlSeeAlso concrete sub class) were very helpful for me to understand what I was really doing.