I am trying to prettyprint in JSON format objects I retrieve from the Java Debug Interface. These objects are the arguments of the method where my breakpoint hit.
My code inside the BreakpointEvent handler is as follows :
// event is the current BreakpointEvent
StackFrame sf = event.thread().frame(0);
for (Value v : sf.getArgumentValues()) {
try {
ObjectMapper mapper = new ObjectMapper();
System.out.println(mapper.writeValueAsString(v));
} catch (Exception e) {
e.printStackTrace();
}
}
However, the only output that I'm getting out of that is a bunch of {"collected":false}
, which is not helpful at all...
I can do the inspection manually, by first checking the precise interface implemented by each v
(interfaces like ArrayReference
, StringReference
, ...), then using the coresponding methods (v.getValues()
for an object implementing ArrayReference
for instance), and doing the same recursively for all values I get.
But manual inspection is more prone to error, and much more heavy in term of code and maintenance. I am confident that Jackson could do the trick here but I'm not getting it to work...