1

我尝试解组一些 xml 文件,但我遇到了泛型类型的问题。如果我设置 @XMLelement(name="ZAP") 它不起作用,但如果我设置 @XmlAnyElement(lax=true) 它起作用。我认为在这种情况下使用@XMLelement 更合适,但我不知道为什么。

'''java

@XmlRootElement(name = "ZL_LIST")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlSeeAlso({ RegistryRecordXmlModelV2.class, 
RegistryRecordXmlModelV30.class, RegistryRecordXmlModelV31.class })
public class RegistryXmlModel <T extends RegistryRecordXmlModel> {

@XmlElement(name = "ZAP")
private List<T> records;
@XmlTransient
private Class<T> recordClazz;
@XmlTransient
private String schema;

public RegistryXmlModel() {
}

public RegistryXmlModel(Class<T> recordClazz) {
    this.recordClazz = recordClazz;
}

public RegistryXmlModel(Class<T> recordClazz, String schema) {
    this.recordClazz = recordClazz;
    this.schema = schema;
}

public List<T> getRecords() {
    return records;
}

public void setRecords(List<T> records) {
    this.records = records;
}

public Class<T> getRecordClazz() {
    return recordClazz;
}

public String getSchema() {
    return schema;
}
}

@XmlRootElement(name = "ZAP")
@XmlAccessorType(XmlAccessType.FIELD)
public class RegistryRecordXmlModelV31 extends 
RegistryRecordXmlAbstractModel<RegistryCaseXmlModelV31> {
@XmlElement(name = "Z_SL")
private RegistryCaseXmlModelV31 caseInfo;

public RegistryRecordXmlModelV31() {
    //default constructor
}

@Override
public RegistryCaseXmlModelV31 getCaseInfo() {
    return caseInfo;
}

public void setCaseInfo(RegistryCaseXmlModelV31 caseInfo) {
    this.caseInfo = caseInfo;
}
}
4

0 回答 0