Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I export or save a inspected object structure in eclipse?

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?

like image 668
ruwan.jayaweera Avatar asked Aug 17 '12 05:08

ruwan.jayaweera


People also ask

How to save a source code file in Eclipse?

As you type in your program, occasionally select File->Save from the menu to save your work. You may enjoy the "content assist" feature of Eclipse. If you type a partial input and then hit CTRL+SPACE, a dialog shows all possible completions. Just pick the one you want from the list.

How do I inspect element in eclipse?

Press Ctrl+Shift+d or Ctrl+Shift+i on a selected variable or expression to show its value. You can also add a permanent watch on an expression/variable that will then be shown in the Expressions view when debugging is on.


1 Answers

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>
like image 173
tostao Avatar answered Oct 31 '22 15:10

tostao