0

Im new here and I have made a game in java. When I am serializing my objects to save the current game, I can deserialize them back normally. But what if I want to make an update for the game (i.e change few classes, add more fields)? When I try to load back the last game after making a change the classes wont fit anymore the the file I serialized to. I want to load all the last game's details and the new fields to be initialized as a default I decide in the code.

p.s - Its not a multiplayer game/requires any connection, the files are saved in the computer the game is installed.

Any suggestions?

Max
  • 1
  • 2
  • You need to provide `private long serialVersionUID`. See http://stackoverflow.com/questions/285793/what-is-a-serialversionuid-and-why-should-i-use-it for more information – Alexander Oct 13 '15 at 09:08

1 Answers1

0

You need to take a long look at the Versioning of Serializable Objects chapter of the Object Serialization Specification. Acquaint yourself thoroughly with what you can and cannot do while maintaining the serialVersionUID constant.

If you think you can't live within those constraints, which are pretty generous, you'll have to use another scheme, e.g. Long Term Persistence.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • If I have a serialized class and i want to remove a field from that class and then deserialize it, it gives me an error. Cant I make the stream ignore the missing field and assign the availble fields? With try and catch? – Max Oct 14 '15 at 08:15