JAXB 非法注释在解析 XML 期间引发异常
这是我的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。谢谢。