Savable vs Serializable

I’m currently working on Saving to disk in my game, and had a question regarding Savable vs Serializable. As I understand it, for all of my custom classes I would need to read/write every single variable manually in order to use Savable, vs Serializable should handle all non-Node related variables just by implementing the interface (assuming nothing like Thread, etc).

This would be a huge undertaking for me to manually write out all of my variables just because a few of my classes extend Node. If this is what I will have to do, I’ll bite the bullet and do it but I was wondering if anyone has run into this before.

If you are saving your game objects then just use whatever you want… Serializable is certainly one valid approach.

If you are saving spatials for some reason (shrug) and have controls or user data then you will obviously need to implement Savable at some level, even if it’s only to write yourself to a serializable byte array.

If your games objects are your spatials then… yeah, you’re going to have a bad time anyway. Just add this one to the list.

may I suggest Jackson ? It rocks !

I suggest that you have a look at Externalizable instead of Serilizable since you probably will having problems when you load old data and you have modified your objects. It’s possible to add a version byte to keep track of versions. Declare your own serialVersionUID as well.

1 Like

Java Serialization is already pretty resilient as long as you manage your serialVersionUID. With externalizable you have to do everything manually but for many of the cases you don’t have to do anything with class changes (adding fields, removing fields… these are taken care of automatically as long as the version is the same).

…then you can override the appropriate read method if you need custom version support.