algesten / jsondiff

Structural JSON diff/patch tool.
Other
66 stars 27 forks source link

Delete null from middle of array produces bad diff #3

Closed deverton closed 12 years ago

deverton commented 12 years ago

Actually, any object type (null, array, object) being deleted from the middle of an array triggers this one.

    @Test
    public void testArrayObjectsWithNullAndChanges() {

        String from = "{\"a\":[{\"c\":2,\"d\":3},null,{\"c\":2,\"d\":3}]}";
        String to = "{\"a\":[{\"c\":2,\"d\":3},{\"c\":2,\"d\":7}]}";
        String diff = "{\"-a[1]\":0,\"~a[2]\":{\"-d\":0},\"~a[1]\":{\"d\":7}}";

        String d = JsonDiff.diff(from, to);
        Assert.assertEquals(diff, d);

        String p = JsonPatch.apply(from, diff);
        Assert.assertEquals(to, p);

    }
algesten commented 12 years ago

This forced me to be much stricter for operation order. Operations are now applied: delete, insert, set, merge.