简体   繁体   English

序列化和反序列化

[英]Serialization and Deserialization

I have several objects that I serialized and now need to edit, is there an approach to this without losing all the data I had stored in the files using the serialization. 我有几个要序列化的对象,现在需要编辑,有没有一种解决方法,而不会丢失使用序列化存储在文件中的所有数据。

EDIT [from comment] I dont need to edit the objects themselves I need to edit the Objects code, such as adding methods to it. 编辑 [注释]我不需要编辑对象本身,也不需要编辑对象代码,例如向其中添加方法。

I dont need to edit the objects themselves I need to edit the Objects code, such as adding methods to it 我不需要编辑对象本身,也不需要编辑对象代码,例如向其中添加方法。

Aha. 啊哈 An actual problem. 一个实际的问题。 OK. 好。

  1. Run the serialver utility on the .class files as they are now. 现在就在.class文件上运行serialver实用程序。

  2. Add the declarations output by serialver to the source code of each class respectively. serialver输出的声明分别添加到每个类的源代码中。

  3. Have a really good look at the Versioning chapter of the Object Serialization Specification to see what you can and cannot do while retaining compatibility with the existing stream. 很好地了解“对象序列化规范”的“ 版本控制”一章,以了解在保持与现有流的兼容性的同时可以做什么和不能做什么。

Load the objects in memory, edit the objects themselves, then save them back. 将对象加载到内存中,编辑对象本身,然后将其保存回去。
This is the safest way of doing it (if not the only way). 这是最安全的方法(如果不是唯一的方法)。

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

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