mercredi 22 avril 2015

Changing from SQLlite table that stores serialized class data to one that stores individual class fields as columns

So recently while trying to add some new functionality to my app I learned the error of my ways in storing serialized data as a BLOB in my SQL table. NOW I see how much of a pain it is to modify, so I'm trying to convert it back to storing each field as a column in the SQL table.

The solution I see is to simply upgrade my SQLLite table to a newer version that has the appropriate schema with the columns to hold the fields of my class. So I would first save the data from the old table, deserialize it into objects of type Foo, then manually add back in the Foo objects, field by field, into the new table. The problem here is that, at the same time, I want to edit Foo so that is has an additional instance variable. If I edit my class then I can no longer deserialize the old serialized data. I guess I could create a new class Foo2 to use so that Foo remains untouched, but I really want to avoid that.

Essentially my question is: is there anyway to change a class that implements Serializable so that old versions can still be read and updated to the new version? If not, what would be the best solution in my situation?

Aucun commentaire:

Enregistrer un commentaire