Are there any serialization/deserialization scenarios that DataContractSerializer can handle, while DataContractJsonSerializer can't?
In particular, I am thinking of circular references: this MSDN page explains how circular references can be managed by DataContractSerializer
via the use of IsReference = true
in the DataContractAttribute
constructor. On the other hand, the DataContractAttribute.IsReference documentation does not explicitly state that its applicability is limited to DataContractSerializer
.
Will DataContractJsonSerializer
also honor the IsReference
property?
There's nothing like a good old hands-on testing in the afternoon...
When applying
DataContractAttribute.IsReference = true
on the class subject to serialization,and trying to serialize it using the
DataContractJsonSerializer
,The
WriteObject
method will throw an exception:If I on the other hand use
DataContractSerializer
to serialize the same object, serialization (and deserialization) works like a charm.Now, if anyone knows of more limitations of
DataContractJsonSerializer
in comparison withDataContractSerializer
, I am all ears...