Skip to content

Instantly share code, notes, and snippets.

@retanoj
Created September 18, 2017 08:33
Show Gist options
  • Save retanoj/57924bec74248c6f1cf57bbaac740631 to your computer and use it in GitHub Desktop.
Save retanoj/57924bec74248c6f1cf57bbaac740631 to your computer and use it in GitHub Desktop.
安全使用xstream fromXML
public static <T> T readValue(String content, Class<T> valueType) {
XStream xstream = new XStream();
// clean rules
xstream.addPermission(NoTypePermission.None);
// only allow Target class type
xstream.allowTypeHierarchy(valueType.class);
return (T) xstream.fromXML(content);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment