algesten/jsondiff — Issue #2: Diffs of field changes in objects in arrays not working
Author: deverton
Created: 2011-11-27 23:51:50+00:00
State: open

Changing field values in objects inside arrays doesn't seem to generate the correct diff. It seems to only affect cases where there's more than one change in the array.

````java
@Test
public void testArrayObjectsChangeField() {
String from = "{\"a\":[{\"c\":2,\"d\":3},{\"c\":2,\"d\":3},{\"c\":2,\"d\":3},{\"c\":2,\"d\":3}]}";
String to = "{\"a\":[{\"c\":2,\"d\":4},{\"c\":2,\"d\":5},{\"c\":2,\"d\":3},{\"c\":2,\"d\":6}]}";
String diff = "{\"~a[0]\":{\"d\":4}}";
// Actually expect something like {~a[0]:{d:4},~a[1]:{d:5},~a[3]:{d:6}}

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

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