-
Notifications
You must be signed in to change notification settings - Fork 9
Embedded Type Maps
Michael Brown edited this page Dec 2, 2018
·
2 revisions
There are some scenarios that cause grief when serializing certain types. Things like abstract interfaces and anonymous types require information about how to serialize them. To solve this, you can choose to embed type information for these scenarios which will increase the size of the serialized data slightly - which is optimized and compressed so it's not that much data.
To embed type descriptors in the serialized data:
var originalObject = new SomeComplexTypeWithDeepStructure();
var bytes = Serializer.Serialize(originalObject, SerializerOptions.EmbedTypes);
var restoredObject = Serializer.Deserialize<SomeComplexTypeWithDeepStructure>(bytes);
Deserialization will detect the type maps automatically and understand how to deserialize the structure.
Important note: If deserializing in a different process or machine, the deserializer needs to have access to the assembly containing the type otherwise deserialization will not be possible.