Add support for conflict resolution (mutated json objects)
maratoss opened this issue · 1 comments
Hi! Is it a bug? Or it is not possible to apply a patch to changed json?
I created a patch on 'a' object, then cleared array of 'a' and tried to apply that patch
but got following error:
[Test]
public void test()
{
var a = new Foo { A = new[] { 1 } };
var b = new Foo { A = new int[0] };
var jsonA = JsonConvert.SerializeObject(a);
var jsonB = JsonConvert.SerializeObject(b);
var jdp = new JsonDiffPatch();
var diff = jdp.Diff(jsonA, jsonB);
/////
a.A = new int[0];
jsonA = JsonConvert.SerializeObject(a);
Console.WriteLine(jdp.Patch(jsonA, diff));
}
private class Foo
{
public int[] A { get; set; }
}
System.ArgumentOutOfRangeException : Index is equal to or greater than Count.
Parameter name: index
at Newtonsoft.Json.Linq.JContainer.RemoveItemAt(Int32 index)
at JsonDiffPatchDotNet.JsonDiffPatch.ArrayPatch(JArray left, JObject patch)
at JsonDiffPatchDotNet.JsonDiffPatch.Patch(JToken left, JToken patch)
at JsonDiffPatchDotNet.JsonDiffPatch.ObjectPatch(JObject obj, JObject patch)
at JsonDiffPatchDotNet.JsonDiffPatch.Patch(JToken left, JToken patch)
at JsonDiffPatchDotNet.JsonDiffPatch.Patch(String left, String patch)
at jtest.test() in jtest.cs:line 29
Currently there is no support in the package for conflict handling other than simply throwing as you see in this example.
I've thought about exposing a ConflictResolution property in the objects class and expose some options like: Strict and IgnoreErrors.
I'll keep this open to track the possibility of adding support for this in the future.