views:

1466

answers:

6

Is there a GUI application that can open serialized Java object files (both binary and XML format) and display them in browsable fashion (maybe like the Eclipse debugger displays the state of variables)?

It needs to work at least partially when not all classes can be resolved (an option to attach extra jars would be nice) or when there are serial version UID mismatches.

Extra points for the ability to make changes.

+3  A: 

Just as a quick and dirty solution:

You could create a simple class in eclipse which loads/deserialises the object.

Put in a breakpoint, and use the eclipse debugging view.

HuibertGill
this is the one i like best: just use eclipse to browse it in the debugger. You can then customize that by creating custom detail formatters
John Gardner
+2  A: 

Just googling around comes up with a few suggestions to start with. Here's a promising one: Java Object Serialization in parsable ASCII format. This is a straight dump and not an Eclipse plugin however (I agree, that would be nice :)). The code is available.

+3  A: 

Ok so I know you want a gui, but heres some code that might set you in the right direction of how this might be implemented.

First deserialization:

 File file = new File(filename);
 ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));

 Object obj = in.readObject();
 in.close();

 return obj;

Once you have the object deserialized, you can use reflection to get the internals (notice how you have to check if it is accessible and if not make it accessible so you can get the actual value:

Class clazz = obj.getClass();
 Field[] fs = clazz.getDeclaredFields();
 for (Field f : fs)
 {
  boolean acc = f.isAccessible();
  if(!acc)
  {
   f.setAccessible(true);
  }

  Object fieldObj = f.get(obj);
  String fieldName = f.getName();
  f.setAccessible(acc);
    }

With that as a basis, you could probably build a tree of the internals of the object and display it to gui similar to what shows up in the eclipse debugger.

I know this isn't what you've asked for, but it might point you in the right direction to an implementation that will handle most of what you want and need.

shsteimer
I am also kind of interested in the many cases where readObject() will fail because not all classes are found, or the serializedVersionId differs.
Thilo
readObject() will throw a ClassDefNotFound, you could just catch that exception, which takes care of the first case by catching that exception. SerialId being different iI'm not sure about.
shsteimer
Yeah, well, but catching the exception does not solve the problem of the readObject() not having worked...
Thilo
+1  A: 

If you are familar with XSL/T, you can serialize the object and output the XML with the XSL stylesheet, you can view the XML from any internet browser.

codemeit
+2  A: 

If you're using a database, the commercial DbVisualizer can display a tree view of serialized Java objects in BLOB columns. Access to class files is not required. Changes do not seem to be possible, through.

Henning
Neat. Are you sure they do not need the class files? I wonder how that works. Still, even if they do, neat.
Thilo
The objects I'm storing are custom classes, but use the default serializer implementation. I haven't tried to use a custom serializer implementation, but you're right, I couldn't imagine how that should work without access to the class files.
Henning
Even using the default serializer, displaying the contents of a custom class without the class definition is great. Seems there is enough information in the stream to find out what is an int, a long, an Object and so on.
Thilo
+1  A: 

The simple tool you are looking for was developed some years ago by a systems research group at St. Andrews University. It is a pity the program is no longer available, but by following the advice given by shsteimer and the guidelines the paper offers, it shouldn't be that hard to develop a home-made one.

Fernando Miguélez
I love the screenshots in that PDF. Flash from the widget past...
Thilo