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

社会主义新天地 提交于 2020-01-01 04:19:10

问题


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


回答1:


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.




回答2:


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.




回答3:


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").



回答4:


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).



来源:https://stackoverflow.com/questions/4889761/does-eclipse-have-an-editor-viewer-for-java-serialized-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!