Java 无法将xml字符串反序列化为扩展的genericType';使用xstream创建对象

Java 无法将xml字符串反序列化为扩展的genericType';使用xstream创建对象,java,generics,xstream,Java,Generics,Xstream,首先,我想展示反序列化xml字符串的核心代码 public XMLClient<T> xmlToClient(String xmlString,T t) throws Exception{ //according to the generic class's name,insert the name after input tag //to make the xstream to know which class is going to deserialize

首先,我想展示反序列化xml字符串的核心代码

    public XMLClient<T> xmlToClient(String xmlString,T t) throws Exception{
    //according to the generic class's name,insert the name after input tag
    //to make the xstream to know which class is going to deserialize to
        String insertClassName = t.getGenericTypeRecord();
        xmlString.replaceAll("<INPUT>", "<INPUT input."+insertClassName+">");
        XMLClient<T> xmlClient = new XMLClient<T>();
        XStream xs = new XStream(new DomDriver());
        xs.processAnnotations(XMLClient.class);
        xmlClient = (XMLClient<T>)xs.fromXML(xmlString);
        logger.info(xmlString);
        return xmlClient;
    }
public-XMLClient-xmlToClient(String-xmlString,T-T)引发异常{
//根据泛型类的名称,在输入标记后插入名称
//使xstream知道将反序列化到哪个类
String insertClassName=t.getGenericTypeRecord();
replaceAll(“,”);
XMLClient XMLClient=新的XMLClient();
XStream xs=newxstream(newdomdriver());
processAnnotations(XMLClient.class);
xmlClient=(xmlClient)xs.fromXML(xmlString);
logger.info(xmlString);
返回xmlClient;
}
T是从超基类扩展而来的a类。 就像

T扩展了baseInputXml

但是当应用程序在

xmlClient = (XMLClient<T>)xs.fromXML(xmlString);
xmlClient=(xmlClient)xs.fromXML(xmlString);
将出现错误消息,告诉我XMLClient中没有匹配的属性。虽然该属性在超级T类中不存在,但在子T类中存在

我希望你能了解我的想法,我对这些genericType和xstream转换非常困惑 多谢各位

该行应编辑为

xs.processAnnotations(XMLClient.class);
xs.processAnnotations(XMLClientsSuperClass.class);

请添加语言标签。
xs.processAnnotations(XMLClient.class);
xs.processAnnotations(XMLClientsSuperClass.class);