I am writing some kind of game on Android. And I am wondering how to save the settings so as not to have problems with updates. For example, I save settings with serialization, I have a GameChar class
public class GameChar implements Serializable{ int health; int damage; Sword sword; }
But later I decided to add value armor to my game character, I change the class:
public class GameChar implements Serializable{ int health; int damage; int armor; Sword sword; }
And now, with the update, I lost all progress because the new GameChar class GameChar not match the GameChar . I have an idea to use Map<String, Object> , where key is the name of the value I save, and the value is any Object I want ( Integer , Float , Calendar or some of my custom Sword class). And I will save this Map file with Serialization .
But if I change some of my custom Sword class, it will not be the same as in my Map , and once again I will lose progress when updating.
Perhaps there is some kind of model or technique that I skip to make it more elegant.
source share