问题描述:

First,I want to show my Core code for deserialize the 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 is the a class extended from the super base class.

just like

T extends baseInputXml

but when the application run at

xmlClient = (XMLClient<T>)xs.fromXML(xmlString);

there will be error message telling me no matching property in XMLClient.although the property does not exist in the super T class ,but exist in the child T class

I wish you could get my idea,I'm really puzzled with these genericType and xstream convert

thank you

网友答案:
xs.processAnnotations(XMLClient.class);

This line should be edited to

xs.processAnnotations(XMLClient.class);
xs.processAnnotations(XMLClientsSuperClass.class);
相关阅读:
Top