Jaxb 编组器和泛型(2)
有类型:
class A{}
@XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
@XmlType(propOrder = {"obj"})
@XmlRootElement(name = "response")
public class B<T extends A> extends A{
private T obj;
@XmlElement(required = true)
public T getObj() {
return obj;
}
}
当我尝试编组这个时,我收到错误:
org.springframework.oxm.MarshallingFailureException: JAXB marshalling exception; nested exception is javax.xml.bind.MarshalException
- with linked exception:
[com.sun.istack.internal.SAXException2: unable to marshal type "com.my.B" as an element because it is missing an @XmlRootElement annotation]
jaxbMarshaller 是否可以与泛型一起使用? 有什么想法吗?
谢谢
there are types:
class A{}
@XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
@XmlType(propOrder = {"obj"})
@XmlRootElement(name = "response")
public class B<T extends A> extends A{
private T obj;
@XmlElement(required = true)
public T getObj() {
return obj;
}
}
When i'm trying to marshal this i get an error:
org.springframework.oxm.MarshallingFailureException: JAXB marshalling exception; nested exception is javax.xml.bind.MarshalException
- with linked exception:
[com.sun.istack.internal.SAXException2: unable to marshal type "com.my.B" as an element because it is missing an @XmlRootElement annotation]
Does jaxbMarshaller work with generic?
Any ideas?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 JAXBContext 是如何创建的?您需要确保它了解 B.class。您可能需要使用@XmlSeeAlso 注释。
给出以下内容:
和:
当我跑步时:
我得到:
当我跑步时:
我得到:
How is your JAXBContext getting created? You will need to ensure that it is aware of B.class. You may need to use the @XmlSeeAlso annotation.
Given the following:
and:
When I run:
I get:
And when I run:
I get: