Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DataContractSerializer: Handling objects whose type you don't know and don't have access to

I have a class (call it Container) which is serialized and deserialized using the DataContractSerializer. The class contains a collection of other classes, all of which inherit the same base class (call it ContentsBase), but which have distinct derived classes. The application may be passed a serialized Container object which contains ContentsBase-derived objects whose implementation I do not know or have access to -- that is, the compiled code is not available locally. I need to deserialize this object by "ignoring" the types I don't know about (I don't need to round-trip them).

Is there any way I can do this, short of taking the serialized XML and writing some custom code to grovel through it and remove unknown elements before deserialization, or is that my only option?

like image 225
technophile Avatar asked Nov 15 '22 16:11

technophile


1 Answers

Serialization surrogates and serialization binder

like image 103
Kristen Avatar answered Dec 17 '22 15:12

Kristen