是否可以配置JAXB上下文(对于unmarshaller)本身,以便它可以实例化具有两个存取器getField()/ setField()和领域? A类不可修改:它是第三方或生成的。配置JAXB解组器处理具有处理器方法和字段的类
class A {
public int field;
public int getField();
public void setField(int field);
}
标准的JAXBContext实例
JAXBContext jaxbContext = JAXBContext.newInstance(A.class);
将给予以下异常
com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
Class has two properties of the same name "field"
this problem is related to the following location:
at public int com.thecompany.A.getField()
at com.thecompany.A
this problem is related to the following location:
at public int com.thecompany.A.field
at com.thecompany.A
这可能与
@XmlAccessorType(XmlAccessType.FIELD)
但这是注释的类来解决不是可接受的解决方案
是否有办法保持类定义不变并且能够从XML文件读取它的实例? (?可能不是JAXB)
UPD:发现回答同一个问题:JAX-B - How to map a schema element to an existing Java class
或者,使用http://wiki.eclipse.org/EclipseLink/Examples/MOXy/GettingStarted作为这样的回答:Creating Jaxb classes from xml without schema;漂亮的教程在http://blog.bdoughan.com/2010/12/extending-jaxb-representing-annotations.html