Persisting Current Game State - Thank You Gson

The scenario is I want to persist the current state of a casual game when the program exits (mainly the scenario where the user hit the back button).  Stuff to be persisted consists of basic primitives, multiple-dimensional arrays of primitives,  and some simple classes that hold the same. I want the framework to handle as much as possible, of course - I don't want to manually write out each field somewhere.  On first thought, standard java serialization enters my mind, but google android folks say it's really really slow, which I'm believing for now.  Using JSON is an option, but I'm still going to have to write and debug a lot of ugh crud serialization/deserializationcode I'd like to avoid.  A viable answer to the need seems to be the use of GSON, which is basically (essentially arbitary) java serialization via JSON, where they handle all the plumbing bits for you.

Initial tests look fine - and it is trivial to use.  It seems to handle a ton of stuff for you. Look forward to getting more warm fuzzies about it.  It might choke on complicated objects, but that's not what I'm looking to mess with.

Note that you'll probably want to change the package name stuff for the gson packages to avoid bugs on some devices - seems some manufacturers included older versions of the gson libraries and inadvertently left them accessible - this will apparently break your gson stuff on those devices.  Workaround is detailed here:

Popular Posts