在我的场景中,我需要在一个对象上一起使用SimpleXML和JaxB注释,这样我就可以使用这个对象来创建不同类型的REST Web服务,我们不想进行任何更新。
我有一节课:
@Root(strict=false)
@XmlRootElement
@XmlAcessorType(XmlAccessType.NONE)
public class Patient{
@Element(name ="id", required = false)
@XmlElement(name="id")
private int patno;
@Element(required = false)
private String lastName;
@Element(required = false)
private String firstName;
// not displaying the getters/setters to save space - but no annotations on those methods.
}
我使用此类的对象来序列化并发送REST POST请求。 REST服务的接口方法注释如下:(这在我的区域之外)
@POST
@Produces(MediaType.APPLICATION_XML)
@Consumes(MediaType.APPLICATION_XML)
public StreamingOutput generatePatientData(final Patient patient);
其他人使用我的同一患者对象为另一个REST服务执行简单的xmlSerialization。
但是发生如下例外:
org.simpleframework.xml.core.PersistenceException: Duplicate annotation of name 'id' on method 'patno'