JAXB 编组超类
我正在编写 Resteasy 服务器应用程序,但无法编组我的超类。我有这样的代码:
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name = "person")
class Person {
protected String name;
@XmlElement(name = "name")
public String getName() { return name; }
public void setName(String name) { this.name = name; }
}
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name = "employee")
class Employee extends Person {
protected Integer id;
@XmlElement(name = "id")
public Integer getId() { return id; }
public void setId(Integer id) { this.id = id; }
}
当我将 Employee 类编组到 XML 时,我得到这样的结果:
<employee>
<id>12345</id>
</employee>
没有从 Person 类继承的 name 字段的输出。
我做错了什么?
谢谢,拉尔夫
I am writing a Resteasy server application and am having trouble getting my superclasses to marshal. I have code something like this:
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name = "person")
class Person {
protected String name;
@XmlElement(name = "name")
public String getName() { return name; }
public void setName(String name) { this.name = name; }
}
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name = "employee")
class Employee extends Person {
protected Integer id;
@XmlElement(name = "id")
public Integer getId() { return id; }
public void setId(Integer id) { this.id = id; }
}
When I marshal the Employee class to XML, I get something like this:
<employee>
<id>12345</id>
</employee>
with no output of the name field inherited from the Person class.
What am I doing wrong?
Thanks, Ralph
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定您如何配置 JAXB 上下文或编组器,但以下内容:-
给出:-
I'm not sure how you're configuring the JAXB context or marshaller but the following:-
gives:-