質問
私は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; }
}
私はXMLにEmployeeクラスをマーシャリングするとき、私はこのような何かを得る:
<employee>
<id>12345</id>
</employee>
nameフィールドの出力なしでは、Personクラスから継承されます。
私が間違って何をしているのですか?
おかげで、ラルフ
解決
-
私はあなたがJAXBコンテキストまたはマーシャラーが、以下の設定をしているかどうかはわかりません
public static void main(String[] args) throws Exception
{
Employee employee = new Employee();
employee.setId(1);
employee.setName("Ralph");
JAXBContext context = JAXBContext.newInstance(Employee.class);
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(employee, System.out);
}
与える: -
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<employee>
<name>Ralph</name>
<id>1</id>
</employee>
所属していません StackOverflow