Reputation: 1206
Is there a way to save/export (also need to be able to view later) an inspected object structure?
Possibly export to a XML or JSON structure?
Upvotes: 6
Views: 4885
Reputation: 529
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)
Upvotes: 0
Reputation: 3068
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>
Upvotes: 2