Json Serialization - Ingore property if it's circular reference
Add into DotVVM Framework an extension, attribute (or anything else) which forces the use of Newtonsoft.Json.PreserveReferencesHandling setting. Specifies reference handling options for the JsonSerializer. https://www.newtonsoft.com/json/help/html/PreserveReferencesHandlingObject.htm
What about attribute?
[ThisViewModelPreserveReferenceWithSetting( enum Newtonsoft.Json.PreserveReferencesHandling )]
public class DefaultViewModel
{
public ObjectWithCircularReferences MyObject { get; set; }
...
public class DefaultViewModel
{
[ThisPropertyPreserveReferenceWithSetting( enum Newtonsoft.Json.PreserveReferencesHandling )]
public ObjectWithCircularReferences MyObject { get; set; }
...
Thank you.
A question that sometimes drives me hazy: am I or are the others crazy? A. E.
Unfortunately, I don't think it's possible to implement the reference handling correctly on the client side. We could either ignore it and simply send the $ref fields back to the server on postbacks, but it will break all value bindings using the object replaced by $ref field, break all staticCommands using the object and it can't be checked when the bindings are compiled. Another possibility would be to implement support for that in the client-side serializer and unwrap the $refed objects, but having the same objects multiple times in ViewModel is not at all good idea because it often completely breaks the page on further serializations/deserializations and leads to unexpected data bindings. And I don't want to implement it.
And with the VDOM update, the client side ViewModel architecture will be very different, it will basically support shared instances in the viewModel, but will never mutate them, which is different behavior from the server-side architecture and will also lead to unexpected behavior.
Replace All ' $ref ' objects as a null objects.
Use it (Allow it) just for properties [Bind(Direction.ServerToClientFirstRequest)].
This data can be sent to the client and can be displayed/deserialized as is.
That means that you couldn't send the data back to server nor display it on the client, what would be the use case? Do I understand you correctly? This would only lead to unexpected behavior.
If you don 't want, no one will change it. :-) But it is possible to implement sending data with circular reference to the client. The Data is serializable.
Developers! Developers! Developers! S. B.
I think it would be fine to have an attribute, that would instruct the serializer to ignore this property it's a backreference - it would basically behave like [Bind(None)] but iff the object is already present in its ancestors.