Created
September 18, 2017 08:33
-
-
Save retanoj/57924bec74248c6f1cf57bbaac740631 to your computer and use it in GitHub Desktop.
安全使用xstream fromXML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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