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?


Solution 1:

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.

Solution 2:

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

Solution 3:

My best workaround to save an object state is to use the Evaluate tool when I have the object in the desired state and using Gson library convert it to a JSON, then at the test setup I copy the JSON as a String and convert it to a Java object again. May be a bit rude but for really large and complex objects it can save you a lot of time.