dart-json-patch
dart-json-patch copied to clipboard
Array moves are not detected by diff
When running a JsonPatch.diff
for what is essentially an array move, a remove and add is generated instead (which can lead to a huge increase in diff size compared to the simple move).
Eg:
final source = [
{'message': '1'},
{'message': '2'},
];
final target = [
{'message': '2'},
{'message': '1'},
];
final diffs = JsonPatch.diff(source, target);
This will generate [{op: remove, path: /1}, {op: add, path: /0, value: {message: 2}}]
instead of the much simpler: [{'op': 'move', 'from': '/0', 'path': '/1'}]
. The latter is accepted by JsonPatch.apply
and produces the correct result.