I am using simpleframework to parse XML string and convert it to an object.
Serializer serializer = new Persister();
try {
Customer model = serializer.read(Customer.class, xmlString);
} catch (Exception e) {
e.printStackTrace();
}
It works well, however I will have a few classes to convert. I made an util method which I call with:
Utils.parseXml(Customer.class, xmlString);
And below an implementation:
public class Utils {
public static <T> T parseXml(T cls, String data) {
Serializer serializer = new Persister();
T model = null;
try {
model = serializer.read(cls, data);
} catch (Exception e) {
e.printStackTrace();
}
return model;
}
}
The problem is that this method returns Class<Customer> instead of Customer which I expect.
What should I do to get a valid result ?
Change
T clsin your method definition toClass<T>.