【发布时间】:2012-04-03 10:34:48
【问题描述】:
这是我的解析器类
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
【问题讨论】:
-
您好,我无法解决绑定问题,我已通过邮件发送,有什么帮助吗?
-
您是否定义了其他元素的映射(
<BXML>、<Order>、...)?如果您只想捕获部分 XML,请查看here。