Different way to make saves from ObjectOutputStream? (version unreadability)

Hello friends,

I have a game and currently we save levels with the ObjectOutputStream, where it just writes all the objects in the level to a data file. This works fine, except for if I update any of the classes saved at all, like adding in a new method or modifying the parameters of an old one. There’s the issue. In something other than a game, I’m sure you can ignore this, but that is simply impossible in a game that may release patches or new versions.

So, what’s a solution? I was thinking I would save all the specific primitives to a file in a certain order, and then construct each object upon loading of the level, but this would get very tedious for so many classes and would mean modifying the load level code each version update. I will do this if nobody can think of a better way, but I wouldn’t be surprised if I’m not the first one who’s dealt with this.

If there is an way in LWJGL, I’ll try that also, as I will eventually convert much of the game to it.

Thanks.

Looks like you arrived at the wrong forum, seeing as there are no ObjectOutputStreams in MIDP and no support for LWJGL.

shmoove

Isn’t J2ME just the standard Java? I could have sworn it was… I guess this should go into game design, then…

So, if any mods wants to delete this…

Any reason why are you using ObjectOutputStreams?
Why not save the data in binary form?
Add a version tag and then if you updated it, the version tag will tell the reader how to read it.

To save reinventing the wheel?

If you want version independance you should override the classes writeObject and readObject implementations with your own loading/saving that is not version sensitive (or atleast offers backward compatability)

Have a look at java.io.Serializable

If you want to do it that way then you need to use Externalizable.

In any case, I reposted and have it all figured out and explained here http://192.18.37.44/forums/index.php?topic=10522.0 if anyone is curious.

We are still talking about J2ME dev, aren’t we?
IIRC there is no ObjectOutputStream under J2ME.
Some devices might have it as a bonus feature but it is not standard.

No, read above. I was thinking J2ME is J2SE, just got my initials messed up. This thread should be deleted, unless you guys feel like talking about file saving in J2ME.

Ah, ok. Now I understand.