我有一个与此类似的代码
@XmlRootElement(name = "root")
@XmlType(propOrder={"param1", "param2""})
public class Demo{
public Demo() {
}
private int param1;
private String param2;
private String param3;
public int getparam1() {
return param1;
}
@XmlElement
public void setparam1(int param1) {
this.param1= param1;
}
//other setters and getters here except for param3
}
但它给了我
n4 counts of IllegalAnnotationExceptions
当我尝试运行程序时出现异常(我在原始代码中总共有6个参数,而且只有4个用于Marshall)
这是什么原因?
答案 0 :(得分:1)
@XmlType anntation中存在错误:
@XmlType(propOrder={"param1", "param2","param3"})
如果这不能解决问题,请尝试检查propOrder中属性的名称或直接使用字段访问者类型:
@XmlRootElement(name = "root")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(propOrder={"param1", "param2", "param3"})
public class Demo{
public Demo() {
}
private int param1;
private String param2;
private String param3;
//getter & setters without annotations
}