JAXB:2个IllegalAnnotationExceptions
计数这是我的分析器类
public class Test {
public static void main(String args[]) throws Exception {
File file = new File("D:\\Test.xml");
JAXBContext jaxbContext = JAXBContext.newInstance(MyOrder.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
MyOrder customer = (MyOrder) jaxbUnmarshaller.unmarshal(file);
System.out.println(customer.getOrder().getSide());
}
}
这是MyOrder.java文件
@XmlRootElement(name = "BXML")
public class MyOrder {
@XmlElement(name = "Bag")
protected Order order;
public MyOrder() {
}
@XmlAttribute
public Order getOrder() {
return order;
}
public void setOrder(Order order) {
this.order = order;
}
}
这是我的域对象( Order.java)
@XmlRootElement(name = "BXML")
public class Order {
public Order() {
}
@XmlAttribute(name = "Side")
protected BigInteger Side;
@XmlValue
public BigInteger getSide() {
return Side;
}
public void setSide(BigInteger side) {
Side = side;
}
}
这是当我试图运行程序
Exception in thread "main" com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions
@XmlAttribute/@XmlValue need to reference a Java type that maps to text in XML.
this problem is related to the following location:
at public com.Order com.MyOrder.getOrder()
at com.MyOrder
Class has two properties of the same name "order"
this problem is related to the following location:
at public com.Order com.MyOrder.getOrder()
at com.MyOrder
this problem is related to the following location:
at protected com.Order com.MyOrder.order
at com.MyOrder
嗨,我能不能够解决问题的结合,我发邮件,任何帮帮我 ? – Pawan 2012-04-03 10:58:19
您是否定义了其他元素的映射('','',...)?如果您只想捕获部分XML,请选中[here](http://stackoverflow.com/questions/8526002)。 –
2012-04-03 13:29:54