1
用MOXY編組時,我遇到了問題。這是XML,我已經解組了。用MOXy編組
<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;
}
我想我錯過了一些東西,任何想法會是什麼呢?
謝謝。