Skip to content

Instantly share code, notes, and snippets.

@JonasGroeger
Created May 29, 2012 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JonasGroeger/2830728 to your computer and use it in GitHub Desktop.
Save JonasGroeger/2830728 to your computer and use it in GitHub Desktop.
How to print the field name and value of an arbitrary object.
public static void logObjectAsJSON(String tag, Object o) {
// In order for this to work you need the XStream library located at http://xstream.codehaus.org/
XStream x = new XStream(new Sun14ReflectionProvider(new FieldDictionary(new ImmutableFieldKeySorter())), new JsonHierarchicalStreamDriver());
Log.d(tag, x.toXML(o));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment