Java: printing an object for debugging

I would like for a simple way to print a java object or to say it another way, serialize the object as a string. I would like to see the values โ€‹โ€‹of all the variables contained within the object, and if there are more objects (like a list or something else), it should also print the material in that object. Basically, it will be something like JSON coding, but JSON does not 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?

+4
source share
2 answers

You can use Gson for serialization in JSON, as it now supports NaN and +/- infinity

+9
source

Most often, ToStringBuilder.reflectionToString (Object) works fine. This will not work with Maps.

+7
source

Source: https://habr.com/ru/post/1348173/


All Articles