?? 1. Define A type of A field, but in instantiation is used in its derived class B,
?? 2. Define A storage base type A collection, but in fact it contains all kinds of derived classes,
?? The above two cases in serialized when there is no problem, but when the deserialization process and cannot be transformed into a derived class,
Excuse me, how should do?
CodePudding user response:
Remember also met a, then use the Attribute to solve this, a back flip code...CodePudding user response:
//belt type serialization deserialization
//string json=JsonConvert. SerializeObject (item ItemObject, new JsonSerializerSettings () {TypeNameHandling=TypeNameHandling. All}));
//var itemObject=JsonConvert. DeserializeObject(json, new JsonSerializerSettings () {TypeNameHandling=TypeNameHandling. All});
CodePudding user response:
I find a piece of code on the Internet, not only can solve the derived class serialization, also can solve the reference cycle, however, this code is for performance, a small string, and deserialization time will takes 3 seconds, so large coffee, please help to solve,
CodePudding user response:
Look at the method 2https://blog.csdn.net/hanjun0612/article/details/59078428
CodePudding user response: