Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save state of object in IntelliJ debug?

Does anyone know whether it is possible to save the state of an object while debugging?

I would like to compare the state of an object in two different execution cycles.

Bonus Question: Anyone with experience in writing IntelliJ plugins? Does the IntelliJ SDK allow to access debug values in debug mode? Read them out of IntelliJ cache and write them to disk?

like image 514
Moritz Schmitz v. Hülst Avatar asked Apr 01 '16 12:04

Moritz Schmitz v. Hülst


People also ask

How do I keep debug points in IntelliJ?

Manage breakpoints To do this, go to Settings/Preferences | Build, Execution, Deployment | Debugger and select Drag to the editor or click with middle mouse button. Clicking a breakpoint will then enable or disable it.

How do I copy an object in debug mode IntelliJ?

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.

How do I change the debug value in IntelliJ?

Select a variable or a property of a complex object in the Debug window, press F2 or right-click and choose Set Value... from the context menu, and then specify a new value and press Enter .

What is drop frame IntelliJ debug?

Drop Frame within the debugger pops the current stack frame and puts control back out to the calling method, resetting any local variables. This is very useful to repeatedly step through a function, but be warned: field mutations or global state changes will remain.


2 Answers

As a very simple solution you can use the Fully Expand Tree Node action for objects in Variables or Watches views. 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.

like image 188
Andrew Terekhine Avatar answered Sep 27 '22 23:09

Andrew Terekhine


To expand on Josep's answer, your best bet is to import Google's Gson library into your project and run:

Gson gson = new Gson(); gson.toJson(yourObject); 

Then copy the value from the result.

Here's an example on IntelliJ IDEA:

example

like image 20
maaw Avatar answered Sep 27 '22 23:09

maaw