MOXyでアンマーシャリングしている間、問題は発生していません。これはXMLです、私はマーシャリングしていません。
<eng><shape type="square"><square-specific>dasdasdas</square-specific></shape></eng>
しかし、マーシャリングすると、次のようになります。
<eng><shape><type/><square-specific>dasdasdas</square-specific></shape></eng>
これが私のモデルファイルです:
@XmlRootElement(name="eng")
public class Eng {
private Shape shape;
public void setShape(Shape shape) {
this.shape = shape;
}
@XmlElement
public Shape getShape() {
return shape;
}
}
@XmlDiscriminatorNode("type")
public abstract class Shape {
}
@XmlDiscriminatorValue("square")
public class Square extends Shape {
private String squareSpecificAttribute;
@XmlElement(name="square-specific")
public String getSquareSpecificAttribute() {
return squareSpecificAttribute;
}
public void setSquareSpecificAttribute(String s) {
this.squareSpecificAttribute = s;
}
}
そして、これは私のコントローラーのメソッドです:
@GET
@Produces(MediaType.APPLICATION_XML)
public Eng get(){
Eng e = new Eng();
Square s = new Square();
s.setSquareSpecificAttribute("dasdasdas");
e.setShape(s);
return e;
}
私は何かが欠けていると思います、それが何であるかについて何か考えはありますか?
ありがとう。