JAXB: 2 tội danh IllegalAnnotationExceptions
Đây là lớp Parser tôi
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());
}
}
Đây là MyOrder.java nộp
@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;
}
}
Đây là đối tượng tên miền của tôi (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;
}
}
Đây là ngoại lệ tôi đang nhận được khi tôi đã cố gắng để chạy các chương trình
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
Hi, tôi có thể không có khả năng giải quyết vấn đề ràng buộc, tôi gửi trong thư, bất kỳ Cứu giúp ? – Pawan
Bạn đã xác định ánh xạ cho các phần tử khác của mình ('', '', ...)? Nếu bạn chỉ muốn nắm bắt một phần của XML, hãy kiểm tra [ở đây] (http://stackoverflow.com/questions/8526002). –