Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for conflict resolution (mutated json objects) #15

Open
maratoss opened this issue May 25, 2017 · 1 comment
Open

Add support for conflict resolution (mutated json objects) #15

maratoss opened this issue May 25, 2017 · 1 comment

Comments

@maratoss
Copy link

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

@wbish
Copy link
Owner

wbish commented May 29, 2017

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.

@wbish wbish changed the title Apply a patch to changed json Add support for conflict resolution (mutated json objects) May 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants