简体   繁体   English

Eclipse是否有java序列化文件的编辑器/查看器?

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

I'm serializing my objects with ObjectOutputStream(FileOutputStream(File)) and deserializing them with the analogous InputStreams . 我正在使用ObjectOutputStream(FileOutputStream(File))序列化我的对象,并使用类似的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? 有没有办法查看这些序列化文件(最好是在eclipse中),所以我可以检查是否写了所有必要的属性?

edit: google search was negative 编辑:谷歌搜索是否定的

Write some tests (using Eclipse's built-in JUnit support). 编写一些测试(使用Eclipse的内置JUnit支持)。

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. “查看”这些文件的唯一方法是使用ObjectInputStream(FileInputStream(File)) ,除非你是字节码大师并使用十六进制编辑器。 If you actually have some testing, there is no need to "look inside" anything. 如果你真的有一些测试,就没有必要“向内看”任何东西。

While this isn't a full fledged editor, Eamonn McManus has written a transcoder which deciphers a serialized blob into a human readable form. 虽然这不是一个完整的编辑器,但Eamonn McManus编写了一个转码器,它将序列化的blob解密为人类可读的形式。 http://weblogs.java.net/blog/2007/06/12/disassembling-serialized-java-objects 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. 如果考虑二进制兼容性和性能,那么现在是查看Externalizable而不是Serializable的好时机。

This is not a "free standing" answer, just an expansion of OrangeDog's answer. 这不是一个“独立”的答案,只是OrangeDog答案的扩展。

"Write some tests (using Eclipse's built-in JUnit support). " “编写一些测试(使用Eclipse内置的JUnit支持)。”

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 ( ie make sure that "all necessary attributes were written" ). 对两个对象进行Compair,以查看反序列化对象包含应该序列化的所有值( 确保“编写了所有必需的属性” )。

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). 然后使用Eclipse的调试视图浏览对象(通过设置断点)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM