javajsontostringinfinitydivide-by-zero

Java: Printing out an object for debugging


I would like an easy way to print out a java object, or to say it another way, serialize an object as a string. I would like to see the values of all variables contained within the object, and if there are more objects (like a list or whatever) it should print out the stuff in that object as well. Basically, it would be something like JSON encoding, but JSON doesn't support infinity, and I need to see if there is infinity or NaN in one of the double or float values.

How can I do this?


Solution

  • You could use Gson to serialize to JSON as it now supports NaN and +/- infinity