[英]Cannot deserialize xml string to the extended genericType's Object using xstream
首先,我想显示我的Core代码以反序列化xml String
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;
}
T是从超级基类扩展的类。 就像
T扩展baseInputXml
但是当应用程序运行在
xmlClient = (XMLClient<T>)xs.fromXML(xmlString);
会出现错误消息,告诉我XMLClient中没有匹配的属性。尽管该属性在超级T类中不存在,但在子T类中存在
我希望您能理解我的想法,我对这些genericType和xstream convert感到非常困惑,谢谢
xs.processAnnotations(XMLClient.class);
该行应编辑为
xs.processAnnotations(XMLClient.class);
xs.processAnnotations(XMLClientsSuperClass.class);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.