Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practice to serialize and deserialize .net objects across versions

Tags:

Objects are serialized to a database using the .NET XML serializer. The object can change over time, and therefore multiple versions exist in the database at one time.

Any suggestions for the best way to construct your code, so that you can still deserialize this object into the latest version. (interfaces / maps / manual serialization etc.)

like image 720
Lee Simpson Avatar asked Mar 06 '09 10:03

Lee Simpson


People also ask

When should I serialize data?

If data is not present on the local member, the system will retrieve that data from another member. This requires serialization for use cases such as: Adding key/value objects to a map. Putting items into a queue, set, or list.

Why do we need to serialize an object in C#?

Serialization allows the developer to save the state of an object and re-create it as needed, providing storage of objects as well as data exchange. Through serialization, a developer can perform actions such as: Sending the object to a remote application by using a web service.

Why do we need to serialize and deserialize?

Serialization is a mechanism of converting the state of an object into a byte stream. Deserialization is the reverse process where the byte stream is used to recreate the actual Java object in memory. This mechanism is used to persist the object. The byte stream created is platform independent.


1 Answers

Have a schema version number in the serialized object. Using custom deserialization, check the version attribute first, and if it turns out to be an old version, upgrade it to the latest schema before deserializing.

like image 189
James L Avatar answered Sep 30 '22 15:09

James L