这是我的 XML 文件:
<fields>
<field mappedField="Num">
</field>
<field mappedField="Type">
</field>
</fields>
我创建了 2 个类来解析它(Fields.java 和 Field.java):
@XmlRootElement(name = "fields")
public class Fields {
@XmlElement(name = "field")
List<Field> fields = new ArrayList<Field>();
//getter, setter
}
和
public class Field {
@XmlAttribute(name = "mappedField")
String mappedField;
//getter,setter
}
但我得到了这个例外:
[INFO] com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
[INFO] at com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:66) ~[na:1.6.0_07]
[INFO] at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:422) ~[na:1.6.0_07]
[INFO] at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:270) ~[na:1.6.0_07]
我不明白为什么会出现这个异常。例外在这里:
JAXBContext context = JAXBContext.newInstance(Fields.class);
我使用 JDK 1.6_0.0.7。谢谢。