Hello again!
I’ve started working on a game, and I’ve made a save file in which I write a serializable object using the following code. The only problem I’m having is that every time I modify one of the classes which are written with the save, the file becomes incompatible with the current version of the software, therefore I need to make a new file everytime I modify something, loosing any backwards compatibility. I was thinking about using json, or even writing each field manually without using automatic serialization. Do you have any recommandations?
public static byte[] serialize(Object object) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
ObjectOutputStream os = new ObjectOutputStream(out);
os.writeObject(object);
return out.toByteArray();
}
public static void writeBytes(File file, byte[] data) throws Exception{
FileOutputStream fileOutputStream = new FileOutputStream(file);
fileOutputStream.write(data);
fileOutputStream.close();
}