6

Is there a way to save/export (also need to be able to view later) an inspected object structure?

sample inspection window in eclipse

Possibly export to a XML or JSON structure?

ruwan.jayaweera
  • 1,196
  • 3
  • 11
  • 25
  • have you looked into the Serializable class? – DMor Aug 17 '12 at 06:11
  • If you just need to view the object, you can highlight it in the tree-structure part of the window above, copy and paste it as plain-text somewhere else. You have to remember to expand all parts of the tree you need though. – matt freake Aug 17 '12 at 12:29

2 Answers2

2

You can use xstream, e.g.

Java objects:

 public class Person {
      private String firstname;
      private String lastname;
      private PhoneNumber phone;
      private PhoneNumber fax;
      // ... constructors and methods
    }

public class PhoneNumber {
  private int code;
  private String number;
  // ... constructors and methods
}'

Simply instantiate the XStream class:

XStream xstream = new XStream();

Create an instance of Person and populate its fields:

Person joe = new Person("Joe", "Walnes");
joe.setPhone(new PhoneNumber(123, "1234-456"));
joe.setFax(new PhoneNumber(123, "9999-999"));

Convert it to XML

String xml = xstream.toXML(joe);'

Result

<person>
  <firstname>Joe</firstname>
  <lastname>Walnes</lastname>
  <phone>
    <code>123</code>
    <number>1234-456</number>
  </phone>
  <fax>
    <code>123</code>
    <number>9999-999</number>
  </fax>
</person>
tostao
  • 2,803
  • 4
  • 38
  • 61
  • 4
    Im not looking for a programmatic solution. I want to examine the structure offline, with out writing additional code (since I'll be doing this a lot) – ruwan.jayaweera Aug 21 '12 at 04:40
0

I think tostao reply is correct, just create a helper class with static method that you will call during debugging that will persist the XML to some file on the system .

Then use Eclipse "expressions" view to execute the command. E.g :

FileUtils.persistObjToXml(obj,path)
C.Champagne
  • 5,381
  • 2
  • 23
  • 35
Mistriel
  • 459
  • 4
  • 9