You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the Deserializer encounters an object reference ("$ref": "2") that was originally defined in a readonly property (get; only), it fails to deserialize and returns null instead.
Class
public class Parent
{
public Child ReadOnlyChild
{
get
{
return Child;
}
}
public Child Child {get; set;}
}
public class Child
{
}
Serialization:
Parent p = new Parent() { Child = new Child() };
JsonConvert.SerializeObject(p, new JsonSerializerSettings()
{ Formatting = Formatting.Indented,
PreserveReferencesHandling = PreserveReferencesHandling.Objects });
Note that sometimes [JsonProperty(Order = #)] is needed to force the serializer to act on ReadOnlyChild first. Regardless, the above Serialized JSON block will fail to deserialize properly, even if the class has been modified to deserialize Child first.
To clarify, the problem is that the Child property is being read as null, not that ReadOnlyChild is unset.
The text was updated successfully, but these errors were encountered:
Stack Overflow Thread
If the Deserializer encounters an object reference (
"$ref": "2"
) that was originally defined in a readonly property (get;
only), it fails to deserialize and returnsnull
instead.Class
Serialization:
Serialized:
Deserialized (& reserialized to show the change):
Note that sometimes
[JsonProperty(Order = #)]
is needed to force the serializer to act onReadOnlyChild
first. Regardless, the above Serialized JSON block will fail to deserialize properly, even if the class has been modified to deserializeChild
first.To clarify, the problem is that the
Child
property is being read asnull
, not thatReadOnlyChild
is unset.The text was updated successfully, but these errors were encountered: