Unable to deserialize type without installer

I have binary serialized objects in a database. They are serialized with protobuf. Now I need to generate some viewer to see the contents of the database. So, I read the stream from the database and deserialize it back to the objects. It works, and the result is a list of objects:

var dbData = readData(someType);//it is IList collection

Now I would like to save this list of objects in a file to see the contents of the database. I thought it was best to save it in xml. So I tried:

var serializer = new XmlSerializer(dbData.GetType());

But I get an error: I can not deserialize the type "My.Entities.IdBase", because it contains the property "Key", which does not have a public setter.

Now what? I cannot change class definitions to have setters. Should I save objects instead of json or plain text? Or should I extract all the properties and values ​​and save them in some xml? Any code sample?

+4
source share
1 answer

JSON.NET will be the answer here. You can find it in nuget. Use it like this:

JsonConvert.DeserializeObject<T>(input);
0
source

Source: https://habr.com/ru/post/1662963/


All Articles