2
votes

I have an entity class which can change over period of time. As of now, I binary serialization to serialize an object of this class. But if I add a new property to the class, I can't deserialize a stream serialized earlier. I tried if I can use BSON with json.net.

I need to take care of these things:

  • Memory footprint of serialized data should be low
  • serialization and deserialization should be fast
  • Need to provide backward compatibility for data serialized with old entity class structure

One approach I considered is to convert the object to IDictionary before serializing it so that I can set default value to properties that are not matching while deserializing. While this works well, it involves additional step to convert the object to IDictionary.

Has anyone faced this situation? what are the approaches you use?

1
Have you looked at Version Tolerant Serialization: msdn.microsoft.com/en-us/library/ms229752%28v=vs.110%29.aspxMike Parkhill
Text-based json with type-hinting can solve the backwards compatibility issue, but may not meet your memory and performance needs.yoyo
@MikeParkhill, this is exactly what I was looking for..!Amit
@yoyo json based approach doesn't work that well for me as quantum of data is hugeAmit
Fair enough, just thought I'd mention it. If anyone else comes here looking for information on backwards-compatible serialization perhaps it will help them.yoyo

1 Answers

1
votes

Actually binary serialization is very flexible. Of course, you can just add [Serializable] attribute to the class and forget about details, but you can also take the full control on serialization by implementing ISerializable interface/by adding methods/attributes which corresponds to the certain steps of serialization/deserialization lifecycle. Considering your question about structure changes, please take a look on the following article.