Entities used to serialize data have changed. How can the serialized data be upgraded for the new entities?
Posted
by
i8abug
on Stack Overflow
See other posts from Stack Overflow
or by i8abug
Published on 2011-01-14T19:00:54Z
Indexed on
2011/01/15
5:54 UTC
Read the original article
Hit count: 163
Hi,
I have a bunch of simple entity instances that I have serialized to a file. In the future, I know that the structure of these entities (ie, maybe I will rename Name to Header or something). The thing is, I don't want to lose the data that I have saved in all these old files. What is the proper way to either
- load the data from the old entities into new entities
- upgrade the old files so that they can be used with new entities
Note: I think I am stuck with binary serialization, not xml serialization.
Thanks in advance!
Edit: So I have an answer for the case I have described. I can use a dataContractSerializer and do something like
[DataMember("bar")]
private string foo;
and change the name in the code and keep the same name that was used for serialization. But what about the following additional cases:
- The original entity has new members which can be serialized
- Some serialized members that were in the original entity are removed
- Some members have actually changed in function (suppose that the original class had a FirstName and LastName member and it has been refactored to have only a FullName member which combines the two)
To handle these, I need some sort of interpreter/translator deserialization class but I have no idea what I should use
© Stack Overflow or respective owner