Rails icon indicating copy to clipboard operation
Rails copied to clipboard

Replace the current java serialization save approach with a xml save approach

Open madoar opened this issue 8 years ago • 3 comments

Currently a game is saved by opening an ObjectOutputStream and then by serializing a GameIOData object, containing some game data and all occurred actions up to now. A game is then loaded by opening an ObjectInputSteam, which is then used to deserialize the a given save file to a GameIOData object.

This approach has a lot of disadvantages. One disadvantage is, that a save file is not easily readable for a human. Another disadvantage is, that changes to the data model often lead a save file incompatibility, because some details, like a variable name or a package name, may have changed.

A more robust approach is using XML for serialization. XML has the huge benefit, that it's readable for a human and modern libraries support the definition of persisted attributes and classes via annotations, which kind of splits the model from the xml schema.

I would suggest to use jackson for the xml export. Details about jackson + xml can be found here: https://github.com/FasterXML/jackson-dataformat-xml.

Some details about the save and load processed: The game state that is saved and loaded is located inside a GameIOData. I would suggest to directly save this object. Therefore this class needs to be enriched with jackson or jaxb annotations (I prefer jaxb, because it's a java standard). Afterwards all referenced classes need to be recursively enriched with the annotations too, otherwise they can not be converted to xml. The loading process happens inside the GameLoader class, while the saving process happens inside the GameSaver class.

madoar avatar Jul 22 '17 18:07 madoar

I have some 300 old locally saved test files. I don't expect that all of these are still loadable, but surely many still are. For these files I would then like to have a conversion tool.

erik-vos avatar Jul 24 '17 09:07 erik-vos

The idea was to automatically convert all save games located in the test folder, when working on this issue. This helps to ensure that the functionality of program is not affected by the changes to the xml save format. I'm not sure if I can provide a tool that you can use afterwards, because the serialization approach depends on the current class structure, which I ultimately want change (see #18 for details). After changing the class structure the conversion will not be possible anymore. My suggestion would be to add these test files as official tests to the git repository, then I'll try to ensure that they are converted.

madoar avatar Jul 25 '17 10:07 madoar

Perhaps it is a better idea to publish your conversion version in a new branch (in the main repo) which I can access, so I can do my stuff my way.

erik-vos avatar Jul 25 '17 15:07 erik-vos