我需要帮助来注释我的类,以便能够正确地将所有属性/元素映射到正确的类。
我有以下xml:
<?xml version="1.0" encoding="UTF-8"?>
<ResourceList xsi:schemaLocation="http://www.example.com CM.xsd" xmlns="http://www.example.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Resource xsi:type="customField" lastModifiedDate="2001-12-17T09:30:47.0Z" dataType="Alphanumeric" required="false" id="customField/1" expiryDate="2001-12-17T09:30:47.0Z" expiryReminder="2" targetClass="copyrightHolder" effectiveDate="2001-12-17T09:30:47.0Z" order="0" maximumLength="0" name="a" minimumLength="0" defaultValue="String"/>
<Resource xsi:type="contact" phoneMobile="String" lastModifiedDate="2001-12-17T09:30:47.0Z" type="a" id="contact/1" phoneOffice="String" email="x@x" expiryDate="2001-12-17T09:30:47.0Z" expiryReminder="2" phoneWork="String" effectiveDate="2001-12-17T09:30:47.0Z" name="a" notify="true"/>
<Resource xsi:type="document" lastModifiedDate="2001-12-17T09:30:47.0Z" id="document/1" filePath="/docs/document1"/>
<Resource xsi:type="copyrightHolder" lastModifiedDate="2001-12-17T09:30:47.0Z" type="a" id="copyrightHolder/1" expiryDate="2001-12-17T09:30:47.0Z" expiryReminder="2" effectiveDate="2001-12-17T09:30:47.0Z" name="a" affiliation="a">
<ExternalId>String</ExternalId>
<ContactId>contact/1</ContactId>
<DocumentId>document/1</DocumentId>
<CustomFieldValue value="String" customFieldId="customField/1"/>
<Address>String</Address>
</Resource>
</ResourceList>
我希望在流程结束时有一个包含属于自定义字段类、联系人类、版权等对象的列表。
这是模型的设计方式。
@XmlSeeAlso({CopyrightHolder.class})
public class AbstractResource {
private String name;
private Date creationDate;
private Date effectiveDate;
private Date expiryDate;
private Long dealExpiryReminder;
private String id;
private String lastModifiedDate;
@XmlAttribute
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@XmlAttribute
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
@XmlAttribute
public Date getEffectiveDate() {
return effectiveDate;
}
public void setEffectiveDate(Date effectiveDate) {
this.effectiveDate = effectiveDate;
}
@XmlAttribute
public Date getExpiryDate() {
return expiryDate;
}
public void setExpiryDate(Date expiryDate) {
this.expiryDate = expiryDate;
}
@XmlAttribute
public Long getDealExpiryReminder() {
return dealExpiryReminder;
}
public void setDealExpiryReminder(Long dealExpiryReminder) {
this.dealExpiryReminder = dealExpiryReminder;
}
@XmlAttribute
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
@XmlAttribute
public String getLastModifiedDate() {
return lastModifiedDate;
}
public void setLastModifiedDate(String lastModifiedDate) {
this.lastModifiedDate = lastModifiedDate;
}
}
public class CoreResource extends AbstractResource{
private List<String> documentIds;
private List<String> contactIds;
private String externalId;
private List<CustomFieldValue> customFieldValues;
@XmlElement
public List<String> getDocumentIds() {
return documentIds;
}
public void setDocumentId(List<String> documentIds) {
this.documentIds = documentIds;
}
@XmlElement
public List<String> getContactIds() {
return contactIds;
}
public void setContactId(List<String> contactId) {
this.contactIds = contactId;
}
@XmlElement
public String getExternalId() {
return externalId;
}
public void setExternalId(String externalId) {
this.externalId = externalId;
}
@XmlElement
public List<CustomFieldValue> getCustomFieldValues() {
return customFieldValues;
}
public void setCustomFieldValue(List<CustomFieldValue> customFieldValues) {
this.customFieldValues = customFieldValues;
}
}
@XmlRootElement(name="ResourceList", namespace="http://www.example.com")
public class ResourceList {
private List<AbstractResource> resourceList;
public Resource[] getResource() {
// TODO Auto-generated method stub
return null;
}
@XmlElement(name="Resource", namespace="http://www.example.com")
public List<AbstractResource> getResourceList() {
return resourceList;
}
public void setResourceList(List<AbstractResource> resourceList) {
this.resourceList = resourceList;
}
}
public class CopyrightHolder extends CoreResource {
private String address;
private String affiliation;
@XmlElement
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
@XmlAttribute
public String getAffiliation() {
return affiliation;
}
public void setAffiliation(String affiliation) {
this.affiliation = affiliation;
}
}
当我摄取 xml 时,我得到了一个 AbstractResources 列表,正如预期的那样,但是我希望这些对象是他的 xml 类型。在这个 xml 中,AbstractResource 的第三个元素是版权所有者,第二个元素是文档,依此类推。
是否可以仅使用注释来实现?如果没有,我该怎么做?
谢谢