Closed
Description
Consider the following source:
[{"name":"a"},{"name":"b"},{"name":"c"}]
And the following target:
[{"name":"b"}]
JsonDiff produces the following patch:
[{"op":"remove","path":"/0"},{"op":"remove","path":"/2"}]
However, if you apply that patch to the original source, you get an exception:
com.github.fge.jsonpatch.JsonPatchException: no such path in target JSON document
com.github.fge.jsonpatch.RemoveOperation.apply(RemoveOperation.java:58)
com.github.fge.jsonpatch.JsonPatch.apply(JsonPatch.java:155)
com.github.fge.jsonpatch.JsonPatch.apply(JsonPatch.java:145)
The issue appears to be that deletes are applied sequentially. The path at index 0 is deleted, but then the resulting array only has length 2. Operating on the shortened array means there is now no path at index 2 to delete. For example the following patch will not throw an exception, however the first and THIRD nodes are deleted, not the first two as might be expected.
[{"op":"remove","path":"/0"},{"op":"remove","path":"/1"}]
Metadata
Metadata
Assignees
Labels
No labels