dart-json-patch icon indicating copy to clipboard operation
dart-json-patch copied to clipboard

Array moves are not detected by diff

Open NicolaVerbeeck opened this issue 3 years ago • 0 comments

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.

NicolaVerbeeck avatar Oct 16 '21 14:10 NicolaVerbeeck