开发者

Best way to update a database's serialized objects after changing the object form

I often write my objects out to a database in xml form.

However, if I change the form of my objects, say by changing the name or by changing the fields, I can no longer read them from the database, which makes somewhat difficult the task of reading them, converting them to their new form, and writing them back out to the database.

I'd rather not have to rename my cla开发者_如何学JAVAsses everytime I change something about them.

*Note: I am relying on C#'s XmlSerialization/Deserialization of objects for generating the Xml. Perhaps this is not desirable if I change the format of the objects.


If you implement the ISerializable interface on your objects, then you can implement custom serialization/deserialization routines that provide backwards compatibility with older versions of the objects.

See here for an example of how it can be done: ISerializable and backward compatibility


It ultimately depends on how you serialize your objects.

One convenient option is to store them as hash (key-value pairs). This way, if to class Dog having property name I add another property breed, existing objects won't be invalidated. They'll just have have breed = nil.
Exact storage format (xml, json or separate 'properties' table) is not important in this case, the important thing is how you convert objects to it and back.

But I don't think anyone could give specific suggestions without knowing specific platform.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜