为什么JAXB无法解析泛型?

时间:2019-07-06 22:06:43

标签: java xml jaxb xmlelement

我尝试解组一些xm​​l文件,但是通用类型有问题。如果我设置@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;
}
}

0 个答案:

没有答案