In the previous post, we discussed handling subtypes during protubuf serialization. In this post, we will continue with serialization and discuss the handling of cyclic references. We will look into how cyclic references could be addressed in 3 key types of serializations. JsonXmlProtobuf As an example of cyclic references, we will address the classic example … Continue reading Handling Cyclic References during Serialization
Tag: Serialize
Conditional Serialization using NewtonSoft Json
One of the least explored feature of Newtonsoft Json is the ability serialize properties conditionally. Consider the hypothetical situation wherein you want to serialize a property in a class only if a condition is satisfied. For example, If the requirement is that you need to include serialize the Department Property only if the User Is … Continue reading Conditional Serialization using NewtonSoft Json
Serializing/Deserializing Dictionaries with Tuple as Key
Sometimes you run into things that might look trivial but it just do not work as expected. One such example is when you attempt to serialize/Deserialize a Dictionary with Tuples as the key. For example The above code would trow an JsonSerializationException when deserializing. But the good part is, the exception tells you exactly what … Continue reading Serializing/Deserializing Dictionaries with Tuple as Key
Quick Intro to Protobuf
Protobuf-net is a .net adaption of Google's Protocol Buffers and is generally considered to be a really fast serialization/deserialization library. The target serializable classes are decorated with mainly 3 attributes. ProtoContract The target class is decorated with the ProtoContract attributes, indicating that the class can be serialized. ProtoMember(N) The ProtoMember attribute indicates the field that … Continue reading Quick Intro to Protobuf
Serialize Deserialize NameValueCollection
Don't ask me why one cannot Serialize/Deserialize a NameValueCollection, but the workaround for the same is based on conversion to dictionary. I ended up writing extension methods to NameValueCollection for serializing and deserializing the collection.