Does Eclipse have an editor/viewer for java serialized files?
Asked Answered
C

5

14

I'm serializing my objects with ObjectOutputStream(FileOutputStream(File)) and deserializing them with the analogous InputStreams. Is there a way to look inside of these serialized files (in eclipse preferably), so I can check, if all necessary attributes were written?

edit: google search was negative

Commeasure answered 3/2, 2011 at 17:55 Comment(2)
I think you mean the other way around.Dubose
Know this is so stupid but... double click in Eclipse (at least Luna and .ser as extension) show the object using default toString()Imagery
D
4

Write some tests (using Eclipse's built-in JUnit support).

The only way to "look inside" these files is to use ObjectInputStream(FileInputStream(File)), unless you're a bytecode guru and use a hex editor. If you actually have some testing, there is no need to "look inside" anything.

Dubose answered 3/2, 2011 at 17:59 Comment(4)
+1 For insisting that testing is the right way to verify serialization.Alwitt
Thank you, I tended to "do" tests, instead of writing them. Your solution gives me motivation to actually write a test ;)Commeasure
Tests are great, but don't help when debugging a production issue in a program you inherited.Encephalograph
@Encephalograph oh yes they doDubose
S
4

While this isn't a full fledged editor, Eamonn McManus has written a transcoder which deciphers a serialized blob into a human readable form. http://weblogs.java.net/blog/2007/06/12/disassembling-serialized-java-objects

If binary compatibility and performance are considerations, this would be a good time to look into Externalizable instead of Serializable.

Ssr answered 4/2, 2011 at 7:57 Comment(1)
The article has dead download link. But the source can be found at github.com/frohoff/serialysis.Duramen
V
2

This is not a "free standing" answer, just an expansion of OrangeDog's answer.

"Write some tests (using Eclipse's built-in JUnit support). "

If you want to test serialization, then write tests that do the following:

  1. Serialize one object to a file.
  2. Deserialize to a different object from the same file.
  3. Compair both objects to see that the deserialized object contains all of the values that were supposed to have been serialized (i.e. make sure that "all necessary attributes were written").
Valvulitis answered 3/2, 2011 at 18:8 Comment(0)
F
1

Write a class which loads the file and deserialises the object. Then use Eclipse's Debugging View to browse the object (by setting a breakpoint).

Forefend answered 3/2, 2011 at 18:1 Comment(0)
E
0

I found SerializationDumper, downloaded its v1.13 binary jar, and was quickly able to read a serialised file.

As you might expect from a tool that doesn't use (or require access to) the corresponding .class files themselves, the text output is quite arcane -- but I was able to decipher the contents of a small object containing a String[], a HashSet and a boolean.

Encephalograph answered 24/1 at 8:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.