KevinDockx / JsonPatch.Dynamic

Support for dynamically typed objects for Marvin.JsonPatch (Json Patch Document RFC 6902 implementation for .NET)
MIT License
8 stars 6 forks source link

Add support for NewtonSoft's JsonExtenstionData #13

Open JoostvdB94 opened 6 years ago

JoostvdB94 commented 6 years ago

Hello Kevin,

Would it be possible to add support for the JsonExtensionData attribute? When modifying a json that is so new, that the model that is serialized to is not yet updated, the JsonExtensionData-Dictionary holds all the non-mapped properties.

When we have the following sequence of messages:

original object (that is serialized to)

public class FooInformation {
    [JsonProperty("foo")]
    public string Foo { get; set; }
}

original json:

{
    "foo":"test"
}

first patch:

{
    {"op":"add", "path":"/bar", "value":["bogus"]}
}

second patch:

{
    {"op":"add", "path":"/bar/-", "value":"rubbish"}
}

The second patch will fail, because FooInformation has no mapping for it. In Newtonsoft.Json, there is a JsonExtensionData attribute that solves the loss of non-mapped fields, and puts those fields in a Dictionary. The /bar-field would be available as an array there, right?

Please consider adding this functionality, as it would add lots of use cases for Json Patch!