Is it possible to get the whole object from debugger as Json?
There is an option View text
but can I somehow View JSON
?
This action is bound to Numpad * key ( * ) by default and opens the whole object tree. Then you select all the elements of opened object tree with shift and copy them to clipboard. You can also use ctrl/cmd-A to select all variables and then copy them.
Search for a key - press CTRL + ALT + SHIFT + F (Windows) or Cmd + Shift + Option + F (MacOS) Right click on the selected text and pick the option: Find Key in JSON.
EDIT: as noted in the comments, this is not perfect, as for some variables you will get a "stackoverflow" response
As suggested by @Mr Han's answer, here's how you can do this:
File | Settings | Build, Execution, Deployment | Debugger | Data Views | Java Type Renderers
+
to add new rendererJSON renderer
java.lang.Object
for Apply renderer to objects of type
Use following expression:
and supply an expression like so:if (null == this || this instanceof String)
return this;
new com.google.gson.GsonBuilder().setPrettyPrinting().create().toJson(this);
OK
Copy Value
on a variable, it will copy as json.
Alternatively, as seen here, you can use the following piece of code in your debug watcher:
new ObjectMapper()
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
.writerWithDefaultPrettyPrinter()
.writeValueAsString( myObject )
You could use the Show as ... plugin for IntelliJ.
A small plugin to display formatted data out of the debugger and console.
Uses IntelliJ's build-in formatting capabilities. No more need to copy values from debugger or console to a file to format them there. Following formats are supported: JSON, SQL, XML, Base64 encoded JSON, Base64 encoded text
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With