algesten/jsondiff — Issue #5: Array insertion causes offset confusion
Author: algesten
Created: 2011-12-01 07:53:09+00:00
State: open
Labels: Bug

When doing multiple insertions, subsequent deletion indexes are wrong causing a bad diff.

@Test
public void testArrayObjectsRemoveAfterMultpleAdd() {

String fr = "{a:[{c:0},{c:1},{c:2},{c:3},{c:4}]}";
String to = "{a:[{e:0},{c:0},{c:2},{e:2},{c:3},{e:3}]}";
String diff = "{\"a[+0]\":{\"e\":0},\"-a[1]\":0,\"a[+3]\":{\"e\":2},\"-a[4]\":0,\"a[+5]\":{\"e\":3}}";

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

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

}