From ad9199b9fe58074a7123776681145ef4bd58607e Mon Sep 17 00:00:00 2001 From: Alexandre Malbosc Date: Fri, 28 Aug 2020 15:53:52 +0200 Subject: [PATCH 1/5] add flag to not generate Move or Copy operations. --- .../fge/jsonpatch/diff/DiffProcessor.java | 14 ++++++++++- .../github/fge/jsonpatch/diff/JsonDiff.java | 25 ++++++++++++++++--- .../fge/jsonpatch/diff/JsonDiffTest.java | 17 ++++++++----- src/test/resources/jsonpatch/diff/diff.json | 23 +++++++++++++++++ 4 files changed, 69 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/github/fge/jsonpatch/diff/DiffProcessor.java b/src/main/java/com/github/fge/jsonpatch/diff/DiffProcessor.java index 299d29a1..3c15a76f 100644 --- a/src/main/java/com/github/fge/jsonpatch/diff/DiffProcessor.java +++ b/src/main/java/com/github/fge/jsonpatch/diff/DiffProcessor.java @@ -36,10 +36,18 @@ final class DiffProcessor private final Map unchanged; + private final boolean withMoveOrCopyOperation; + public static final boolean WITH_MOVE_OR_COPY_OPERATION = true; + private final List diffs = new ArrayList(); - DiffProcessor(final Map unchanged) + DiffProcessor(final Map unchanged) { + this(unchanged, WITH_MOVE_OR_COPY_OPERATION); + } + + DiffProcessor(final Map unchanged, boolean withMoveOrCopyOperation) { + this.withMoveOrCopyOperation = withMoveOrCopyOperation; this.unchanged = Collections.unmodifiableMap(new HashMap(unchanged)); } @@ -56,6 +64,10 @@ void valueRemoved(final JsonPointer pointer, final JsonNode value) void valueAdded(final JsonPointer pointer, final JsonNode value) { + if (!withMoveOrCopyOperation) { + diffs.add(DiffOperation.add(pointer, value)); + return; + } final int removalIndex = findPreviouslyRemoved(value); if (removalIndex != -1) { final DiffOperation removed = diffs.get(removalIndex); diff --git a/src/main/java/com/github/fge/jsonpatch/diff/JsonDiff.java b/src/main/java/com/github/fge/jsonpatch/diff/JsonDiff.java index 302a79c2..b485b7a1 100644 --- a/src/main/java/com/github/fge/jsonpatch/diff/JsonDiff.java +++ b/src/main/java/com/github/fge/jsonpatch/diff/JsonDiff.java @@ -36,6 +36,8 @@ import java.io.IOException; import java.util.*; +import static com.github.fge.jsonpatch.diff.DiffProcessor.WITH_MOVE_OR_COPY_OPERATION; + /** * JSON "diff" implementation * @@ -81,14 +83,25 @@ private JsonDiff() * * @since 1.9 */ + +// public static JsonPatch asJsonPatch(final JsonNode source, +// final JsonNode target, false) +// { +// return +// } public static JsonPatch asJsonPatch(final JsonNode source, - final JsonNode target) + final JsonNode target) + { + return asJsonPatch(source, target, WITH_MOVE_OR_COPY_OPERATION); + } + public static JsonPatch asJsonPatch(final JsonNode source, + final JsonNode target, final boolean withMoveOrCopyOperation) { BUNDLE.checkNotNull(source, "common.nullArgument"); BUNDLE.checkNotNull(target, "common.nullArgument"); final Map unchanged = getUnchangedValues(source, target); - final DiffProcessor processor = new DiffProcessor(unchanged); + final DiffProcessor processor = new DiffProcessor(unchanged, withMoveOrCopyOperation); generateDiffs(processor, JsonPointer.empty(), source, target); return processor.getPatch(); @@ -103,10 +116,16 @@ public static JsonPatch asJsonPatch(final JsonNode source, * @return the patch as a {@link JsonNode} */ public static JsonNode asJson(final JsonNode source, final JsonNode target) + { + return asJson(source, target, WITH_MOVE_OR_COPY_OPERATION); + } + + + public static JsonNode asJson(final JsonNode source, final JsonNode target, final boolean withMoveOrCopyOperation) { final String s; try { - s = MAPPER.writeValueAsString(asJsonPatch(source, target)); + s = MAPPER.writeValueAsString(asJsonPatch(source, target, withMoveOrCopyOperation)); return MAPPER.readTree(s); } catch (IOException e) { throw new RuntimeException("cannot generate JSON diff", e); diff --git a/src/test/java/com/github/fge/jsonpatch/diff/JsonDiffTest.java b/src/test/java/com/github/fge/jsonpatch/diff/JsonDiffTest.java index 1a8d0ac5..9502a304 100644 --- a/src/test/java/com/github/fge/jsonpatch/diff/JsonDiffTest.java +++ b/src/test/java/com/github/fge/jsonpatch/diff/JsonDiffTest.java @@ -32,6 +32,7 @@ import java.util.Iterator; import java.util.List; +import static com.github.fge.jsonpatch.diff.DiffProcessor.WITH_MOVE_OR_COPY_OPERATION; import static org.assertj.core.api.Assertions.assertThat; public final class JsonDiffTest @@ -53,17 +54,20 @@ public Iterator getPatchesOnly() final List list = Lists.newArrayList(); for (final JsonNode node: testData) - list.add(new Object[] { node.get("first"), node.get("second") }); + list.add(new Object[] { + node.get("first"), node.get("second"), + node.has("withMoveOrCopy") ? node.get("withMoveOrCopy").booleanValue() : WITH_MOVE_OR_COPY_OPERATION + }); return list.iterator(); } @Test(dataProvider = "getPatchesOnly") public void generatedPatchAppliesCleanly(final JsonNode first, - final JsonNode second) + final JsonNode second, final boolean withMoveOrCopy) throws JsonPatchException { - final JsonPatch patch = JsonDiff.asJsonPatch(first, second); + final JsonPatch patch = JsonDiff.asJsonPatch(first, second, withMoveOrCopy); final JsonNode actual = patch.apply(first); assertThat(EQUIVALENCE.equivalent(second, actual)).overridingErrorMessage( @@ -82,7 +86,8 @@ public Iterator getLiteralPatches() continue; list.add(new Object[] { node.get("message").textValue(), node.get("first"), - node.get("second"), node.get("patch") + node.get("second"), node.get("patch"), + node.has("withMoveOrCopy") ? node.get("withMoveOrCopy").booleanValue() : WITH_MOVE_OR_COPY_OPERATION }); } @@ -94,9 +99,9 @@ public Iterator getLiteralPatches() dependsOnMethods = "generatedPatchAppliesCleanly" ) public void generatedPatchesAreWhatIsExpected(final String message, - final JsonNode first, final JsonNode second, final JsonNode expected) + final JsonNode first, final JsonNode second, final JsonNode expected, final boolean withMoveOrCopyOperation) { - final JsonNode actual = JsonDiff.asJson(first, second); + final JsonNode actual = JsonDiff.asJson(first, second, withMoveOrCopyOperation); assertThat(EQUIVALENCE.equivalent(expected, actual)).overridingErrorMessage( "patch is not what was expected\nscenario: %s\n" diff --git a/src/test/resources/jsonpatch/diff/diff.json b/src/test/resources/jsonpatch/diff/diff.json index 243aef12..4f99c488 100644 --- a/src/test/resources/jsonpatch/diff/diff.json +++ b/src/test/resources/jsonpatch/diff/diff.json @@ -134,5 +134,28 @@ "patch": [ { "op": "move", "path": "/c", "from": "/a" } ] + },{ + "message": "similar element is copied instead of added", + "first": { + "a": "c" + }, + "second": { + "a": "c", + "d": "c" + }, + "patch": [ + { "op": "add", "path": "/d", "value": "c" } + ], + "withMoveOrCopy": false + }, + { + "message": "similar element removed then added is moved instead", + "first": { "a": "b" }, + "second": { "c": "b" }, + "patch": [ + { "op": "remove", "path": "/a" }, + { "op": "add", "path": "/c", "value": "b" } + ], + "withMoveOrCopy": false } ] \ No newline at end of file From 51cf32f46aa1854205e252802578a1029ff4841a Mon Sep 17 00:00:00 2001 From: Alexandre Malbosc Date: Fri, 4 Sep 2020 12:02:59 +0200 Subject: [PATCH 2/5] rename flag about move or copy operations to 'diffDoesntRequireSource' --- .../com/github/fge/jsonpatch/diff/DiffProcessor.java | 12 ++++++------ .../java/com/github/fge/jsonpatch/diff/JsonDiff.java | 10 +++++----- .../com/github/fge/jsonpatch/diff/JsonDiffTest.java | 10 +++++----- src/test/resources/jsonpatch/diff/diff.json | 4 ++-- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/github/fge/jsonpatch/diff/DiffProcessor.java b/src/main/java/com/github/fge/jsonpatch/diff/DiffProcessor.java index 3c15a76f..c9321347 100644 --- a/src/main/java/com/github/fge/jsonpatch/diff/DiffProcessor.java +++ b/src/main/java/com/github/fge/jsonpatch/diff/DiffProcessor.java @@ -36,18 +36,18 @@ final class DiffProcessor private final Map unchanged; - private final boolean withMoveOrCopyOperation; - public static final boolean WITH_MOVE_OR_COPY_OPERATION = true; + private final boolean diffDoesntRequireSource; + public static final boolean DIFF_DOESNT_REQUIRE_SOURCE = false; private final List diffs = new ArrayList(); DiffProcessor(final Map unchanged) { - this(unchanged, WITH_MOVE_OR_COPY_OPERATION); + this(unchanged, DIFF_DOESNT_REQUIRE_SOURCE); } - DiffProcessor(final Map unchanged, boolean withMoveOrCopyOperation) + DiffProcessor(final Map unchanged, boolean diffDoesntRequireSource) { - this.withMoveOrCopyOperation = withMoveOrCopyOperation; + this.diffDoesntRequireSource = diffDoesntRequireSource; this.unchanged = Collections.unmodifiableMap(new HashMap(unchanged)); } @@ -64,7 +64,7 @@ void valueRemoved(final JsonPointer pointer, final JsonNode value) void valueAdded(final JsonPointer pointer, final JsonNode value) { - if (!withMoveOrCopyOperation) { + if (diffDoesntRequireSource) { diffs.add(DiffOperation.add(pointer, value)); return; } diff --git a/src/main/java/com/github/fge/jsonpatch/diff/JsonDiff.java b/src/main/java/com/github/fge/jsonpatch/diff/JsonDiff.java index b485b7a1..831b0e94 100644 --- a/src/main/java/com/github/fge/jsonpatch/diff/JsonDiff.java +++ b/src/main/java/com/github/fge/jsonpatch/diff/JsonDiff.java @@ -36,7 +36,7 @@ import java.io.IOException; import java.util.*; -import static com.github.fge.jsonpatch.diff.DiffProcessor.WITH_MOVE_OR_COPY_OPERATION; +import static com.github.fge.jsonpatch.diff.DiffProcessor.DIFF_DOESNT_REQUIRE_SOURCE; /** * JSON "diff" implementation @@ -92,16 +92,16 @@ private JsonDiff() public static JsonPatch asJsonPatch(final JsonNode source, final JsonNode target) { - return asJsonPatch(source, target, WITH_MOVE_OR_COPY_OPERATION); + return asJsonPatch(source, target, DIFF_DOESNT_REQUIRE_SOURCE); } public static JsonPatch asJsonPatch(final JsonNode source, - final JsonNode target, final boolean withMoveOrCopyOperation) + final JsonNode target, final boolean diffDoesntRequireSource) { BUNDLE.checkNotNull(source, "common.nullArgument"); BUNDLE.checkNotNull(target, "common.nullArgument"); final Map unchanged = getUnchangedValues(source, target); - final DiffProcessor processor = new DiffProcessor(unchanged, withMoveOrCopyOperation); + final DiffProcessor processor = new DiffProcessor(unchanged, diffDoesntRequireSource); generateDiffs(processor, JsonPointer.empty(), source, target); return processor.getPatch(); @@ -117,7 +117,7 @@ public static JsonPatch asJsonPatch(final JsonNode source, */ public static JsonNode asJson(final JsonNode source, final JsonNode target) { - return asJson(source, target, WITH_MOVE_OR_COPY_OPERATION); + return asJson(source, target, DIFF_DOESNT_REQUIRE_SOURCE); } diff --git a/src/test/java/com/github/fge/jsonpatch/diff/JsonDiffTest.java b/src/test/java/com/github/fge/jsonpatch/diff/JsonDiffTest.java index 9502a304..f93132de 100644 --- a/src/test/java/com/github/fge/jsonpatch/diff/JsonDiffTest.java +++ b/src/test/java/com/github/fge/jsonpatch/diff/JsonDiffTest.java @@ -32,7 +32,7 @@ import java.util.Iterator; import java.util.List; -import static com.github.fge.jsonpatch.diff.DiffProcessor.WITH_MOVE_OR_COPY_OPERATION; +import static com.github.fge.jsonpatch.diff.DiffProcessor.DIFF_DOESNT_REQUIRE_SOURCE; import static org.assertj.core.api.Assertions.assertThat; public final class JsonDiffTest @@ -56,7 +56,7 @@ public Iterator getPatchesOnly() for (final JsonNode node: testData) list.add(new Object[] { node.get("first"), node.get("second"), - node.has("withMoveOrCopy") ? node.get("withMoveOrCopy").booleanValue() : WITH_MOVE_OR_COPY_OPERATION + node.has("diffDoesntRequireSource") ? node.get("diffDoesntRequireSource").booleanValue() : DIFF_DOESNT_REQUIRE_SOURCE }); return list.iterator(); @@ -87,7 +87,7 @@ public Iterator getLiteralPatches() list.add(new Object[] { node.get("message").textValue(), node.get("first"), node.get("second"), node.get("patch"), - node.has("withMoveOrCopy") ? node.get("withMoveOrCopy").booleanValue() : WITH_MOVE_OR_COPY_OPERATION + node.has("diffDoesntRequireSource") ? node.get("diffDoesntRequireSource").booleanValue() : DIFF_DOESNT_REQUIRE_SOURCE }); } @@ -99,9 +99,9 @@ public Iterator getLiteralPatches() dependsOnMethods = "generatedPatchAppliesCleanly" ) public void generatedPatchesAreWhatIsExpected(final String message, - final JsonNode first, final JsonNode second, final JsonNode expected, final boolean withMoveOrCopyOperation) + final JsonNode first, final JsonNode second, final JsonNode expected, final boolean diffDoesntRequireSource) { - final JsonNode actual = JsonDiff.asJson(first, second, withMoveOrCopyOperation); + final JsonNode actual = JsonDiff.asJson(first, second, diffDoesntRequireSource); assertThat(EQUIVALENCE.equivalent(expected, actual)).overridingErrorMessage( "patch is not what was expected\nscenario: %s\n" diff --git a/src/test/resources/jsonpatch/diff/diff.json b/src/test/resources/jsonpatch/diff/diff.json index 4f99c488..7d1d4bd6 100644 --- a/src/test/resources/jsonpatch/diff/diff.json +++ b/src/test/resources/jsonpatch/diff/diff.json @@ -146,7 +146,7 @@ "patch": [ { "op": "add", "path": "/d", "value": "c" } ], - "withMoveOrCopy": false + "diffDoesntRequireSource": true }, { "message": "similar element removed then added is moved instead", @@ -156,6 +156,6 @@ { "op": "remove", "path": "/a" }, { "op": "add", "path": "/c", "value": "b" } ], - "withMoveOrCopy": false + "diffDoesntRequireSource": true } ] \ No newline at end of file From d7363df31a3745511a8d1cc3162cdca3c185e2bc Mon Sep 17 00:00:00 2001 From: Alexandre Malbosc Date: Thu, 24 Sep 2020 14:09:22 +0200 Subject: [PATCH 3/5] add DiffOptions class --- .../fge/jsonpatch/diff/DiffOptions.java | 40 +++++++++++++++++++ .../fge/jsonpatch/diff/DiffProcessor.java | 10 ++--- .../github/fge/jsonpatch/diff/JsonDiff.java | 12 +++--- .../fge/jsonpatch/diff/JsonDiffTest.java | 26 ++++++++---- src/test/resources/jsonpatch/diff/diff.json | 24 +++++++++-- 5 files changed, 90 insertions(+), 22 deletions(-) create mode 100644 src/main/java/com/github/fge/jsonpatch/diff/DiffOptions.java diff --git a/src/main/java/com/github/fge/jsonpatch/diff/DiffOptions.java b/src/main/java/com/github/fge/jsonpatch/diff/DiffOptions.java new file mode 100644 index 00000000..ec040d73 --- /dev/null +++ b/src/main/java/com/github/fge/jsonpatch/diff/DiffOptions.java @@ -0,0 +1,40 @@ +package com.github.fge.jsonpatch.diff; + +/** + * Created by AMA on 24/09/2020. + */ +public class DiffOptions { + + public static final boolean DIFF_DOESNT_REQUIRE_SOURCE = false; + + final boolean diffDoesntRequireSource; + + public static final DiffOptions DEFAULT_OPTIONS = new DiffOptions(DIFF_DOESNT_REQUIRE_SOURCE); + + private DiffOptions(boolean diffDoesntRequireSource) { + this.diffDoesntRequireSource = diffDoesntRequireSource; + } + + public boolean isDiffDoesntRequireSource() { + return diffDoesntRequireSource; + } + + public static class Builder { + private boolean diffDoesntRequireSource = DIFF_DOESNT_REQUIRE_SOURCE; + + public Builder diffDoesntRequireSource() { + diffDoesntRequireSource = true; + return this; + } + + public Builder diffRequireSource() { + diffDoesntRequireSource = false; + return this; + } + + public DiffOptions build(){ + return new DiffOptions(diffDoesntRequireSource); + } + + } +} diff --git a/src/main/java/com/github/fge/jsonpatch/diff/DiffProcessor.java b/src/main/java/com/github/fge/jsonpatch/diff/DiffProcessor.java index c9321347..9152925f 100644 --- a/src/main/java/com/github/fge/jsonpatch/diff/DiffProcessor.java +++ b/src/main/java/com/github/fge/jsonpatch/diff/DiffProcessor.java @@ -36,18 +36,18 @@ final class DiffProcessor private final Map unchanged; - private final boolean diffDoesntRequireSource; + private final DiffOptions options; public static final boolean DIFF_DOESNT_REQUIRE_SOURCE = false; private final List diffs = new ArrayList(); DiffProcessor(final Map unchanged) { - this(unchanged, DIFF_DOESNT_REQUIRE_SOURCE); + this(unchanged, DiffOptions.DEFAULT_OPTIONS); } - DiffProcessor(final Map unchanged, boolean diffDoesntRequireSource) + DiffProcessor(final Map unchanged, DiffOptions options) { - this.diffDoesntRequireSource = diffDoesntRequireSource; + this.options = options; this.unchanged = Collections.unmodifiableMap(new HashMap(unchanged)); } @@ -64,7 +64,7 @@ void valueRemoved(final JsonPointer pointer, final JsonNode value) void valueAdded(final JsonPointer pointer, final JsonNode value) { - if (diffDoesntRequireSource) { + if (options.isDiffDoesntRequireSource()) { diffs.add(DiffOperation.add(pointer, value)); return; } diff --git a/src/main/java/com/github/fge/jsonpatch/diff/JsonDiff.java b/src/main/java/com/github/fge/jsonpatch/diff/JsonDiff.java index 831b0e94..11a73bf7 100644 --- a/src/main/java/com/github/fge/jsonpatch/diff/JsonDiff.java +++ b/src/main/java/com/github/fge/jsonpatch/diff/JsonDiff.java @@ -92,16 +92,16 @@ private JsonDiff() public static JsonPatch asJsonPatch(final JsonNode source, final JsonNode target) { - return asJsonPatch(source, target, DIFF_DOESNT_REQUIRE_SOURCE); + return asJsonPatch(source, target, DiffOptions.DEFAULT_OPTIONS); } public static JsonPatch asJsonPatch(final JsonNode source, - final JsonNode target, final boolean diffDoesntRequireSource) + final JsonNode target, DiffOptions options) { BUNDLE.checkNotNull(source, "common.nullArgument"); BUNDLE.checkNotNull(target, "common.nullArgument"); final Map unchanged = getUnchangedValues(source, target); - final DiffProcessor processor = new DiffProcessor(unchanged, diffDoesntRequireSource); + final DiffProcessor processor = new DiffProcessor(unchanged, options); generateDiffs(processor, JsonPointer.empty(), source, target); return processor.getPatch(); @@ -117,15 +117,15 @@ public static JsonPatch asJsonPatch(final JsonNode source, */ public static JsonNode asJson(final JsonNode source, final JsonNode target) { - return asJson(source, target, DIFF_DOESNT_REQUIRE_SOURCE); + return asJson(source, target, DiffOptions.DEFAULT_OPTIONS); } - public static JsonNode asJson(final JsonNode source, final JsonNode target, final boolean withMoveOrCopyOperation) + public static JsonNode asJson(final JsonNode source, final JsonNode target, DiffOptions options) { final String s; try { - s = MAPPER.writeValueAsString(asJsonPatch(source, target, withMoveOrCopyOperation)); + s = MAPPER.writeValueAsString(asJsonPatch(source, target, options)); return MAPPER.readTree(s); } catch (IOException e) { throw new RuntimeException("cannot generate JSON diff", e); diff --git a/src/test/java/com/github/fge/jsonpatch/diff/JsonDiffTest.java b/src/test/java/com/github/fge/jsonpatch/diff/JsonDiffTest.java index f93132de..00287f37 100644 --- a/src/test/java/com/github/fge/jsonpatch/diff/JsonDiffTest.java +++ b/src/test/java/com/github/fge/jsonpatch/diff/JsonDiffTest.java @@ -33,7 +33,7 @@ import java.util.List; import static com.github.fge.jsonpatch.diff.DiffProcessor.DIFF_DOESNT_REQUIRE_SOURCE; -import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.*; public final class JsonDiffTest { @@ -56,7 +56,7 @@ public Iterator getPatchesOnly() for (final JsonNode node: testData) list.add(new Object[] { node.get("first"), node.get("second"), - node.has("diffDoesntRequireSource") ? node.get("diffDoesntRequireSource").booleanValue() : DIFF_DOESNT_REQUIRE_SOURCE + node.has("options") ? getLiteralOptions(node.get("options")) : DiffOptions.DEFAULT_OPTIONS }); return list.iterator(); @@ -64,10 +64,10 @@ public Iterator getPatchesOnly() @Test(dataProvider = "getPatchesOnly") public void generatedPatchAppliesCleanly(final JsonNode first, - final JsonNode second, final boolean withMoveOrCopy) + final JsonNode second, final DiffOptions options) throws JsonPatchException { - final JsonPatch patch = JsonDiff.asJsonPatch(first, second, withMoveOrCopy); + final JsonPatch patch = JsonDiff.asJsonPatch(first, second, options); final JsonNode actual = patch.apply(first); assertThat(EQUIVALENCE.equivalent(second, actual)).overridingErrorMessage( @@ -87,21 +87,33 @@ public Iterator getLiteralPatches() list.add(new Object[] { node.get("message").textValue(), node.get("first"), node.get("second"), node.get("patch"), - node.has("diffDoesntRequireSource") ? node.get("diffDoesntRequireSource").booleanValue() : DIFF_DOESNT_REQUIRE_SOURCE + node.has("options") ? getLiteralOptions(node.get("options")) : DiffOptions.DEFAULT_OPTIONS }); } return list.iterator(); } + public DiffOptions getLiteralOptions(JsonNode jsonNode) { + DiffOptions.Builder builder = new DiffOptions.Builder(); + if (jsonNode.has("diffDoesntRequireSource")) { + if (jsonNode.get("diffDoesntRequireSource").booleanValue()){ + builder.diffDoesntRequireSource(); + } else { + builder.diffRequireSource(); + } + } + return builder.build(); + } + @Test( dataProvider = "getLiteralPatches", dependsOnMethods = "generatedPatchAppliesCleanly" ) public void generatedPatchesAreWhatIsExpected(final String message, - final JsonNode first, final JsonNode second, final JsonNode expected, final boolean diffDoesntRequireSource) + final JsonNode first, final JsonNode second, final JsonNode expected, final DiffOptions options) { - final JsonNode actual = JsonDiff.asJson(first, second, diffDoesntRequireSource); + final JsonNode actual = JsonDiff.asJson(first, second, options); assertThat(EQUIVALENCE.equivalent(expected, actual)).overridingErrorMessage( "patch is not what was expected\nscenario: %s\n" diff --git a/src/test/resources/jsonpatch/diff/diff.json b/src/test/resources/jsonpatch/diff/diff.json index 7d1d4bd6..d2e27336 100644 --- a/src/test/resources/jsonpatch/diff/diff.json +++ b/src/test/resources/jsonpatch/diff/diff.json @@ -135,7 +135,7 @@ { "op": "move", "path": "/c", "from": "/a" } ] },{ - "message": "similar element is copied instead of added", + "message": "when diffDoesntRequireSource similar element is added", "first": { "a": "c" }, @@ -146,16 +146,32 @@ "patch": [ { "op": "add", "path": "/d", "value": "c" } ], - "diffDoesntRequireSource": true + "options": { + "diffDoesntRequireSource": true + } }, { - "message": "similar element removed then added is moved instead", + "message": "when diffDoesntRequireSource similar element is removed then added", "first": { "a": "b" }, "second": { "c": "b" }, "patch": [ { "op": "remove", "path": "/a" }, { "op": "add", "path": "/c", "value": "b" } ], - "diffDoesntRequireSource": true + "options": { + "diffDoesntRequireSource": true + } + + }, + { + "message": "with default options, similar element removed then added is moved instead", + "first": { "a": "b" }, + "second": { "c": "b" }, + "patch": [ + { "op": "move", "path": "/c", "from": "/a" } + ], + "options": { + } + } ] \ No newline at end of file From 94a7d546a11e8af91d600a05fffb919c1f5d8a7c Mon Sep 17 00:00:00 2001 From: Alexandre Malbosc Date: Thu, 24 Sep 2020 15:13:52 +0200 Subject: [PATCH 4/5] options param should be final --- .../java/com/github/fge/jsonpatch/diff/DiffProcessor.java | 2 +- src/main/java/com/github/fge/jsonpatch/diff/JsonDiff.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/github/fge/jsonpatch/diff/DiffProcessor.java b/src/main/java/com/github/fge/jsonpatch/diff/DiffProcessor.java index 9152925f..75ed074a 100644 --- a/src/main/java/com/github/fge/jsonpatch/diff/DiffProcessor.java +++ b/src/main/java/com/github/fge/jsonpatch/diff/DiffProcessor.java @@ -45,7 +45,7 @@ final class DiffProcessor this(unchanged, DiffOptions.DEFAULT_OPTIONS); } - DiffProcessor(final Map unchanged, DiffOptions options) + DiffProcessor(final Map unchanged, final DiffOptions options) { this.options = options; this.unchanged = Collections.unmodifiableMap(new HashMap(unchanged)); diff --git a/src/main/java/com/github/fge/jsonpatch/diff/JsonDiff.java b/src/main/java/com/github/fge/jsonpatch/diff/JsonDiff.java index 11a73bf7..dccf9d71 100644 --- a/src/main/java/com/github/fge/jsonpatch/diff/JsonDiff.java +++ b/src/main/java/com/github/fge/jsonpatch/diff/JsonDiff.java @@ -95,7 +95,7 @@ public static JsonPatch asJsonPatch(final JsonNode source, return asJsonPatch(source, target, DiffOptions.DEFAULT_OPTIONS); } public static JsonPatch asJsonPatch(final JsonNode source, - final JsonNode target, DiffOptions options) + final JsonNode target, final DiffOptions options) { BUNDLE.checkNotNull(source, "common.nullArgument"); BUNDLE.checkNotNull(target, "common.nullArgument"); @@ -121,7 +121,7 @@ public static JsonNode asJson(final JsonNode source, final JsonNode target) } - public static JsonNode asJson(final JsonNode source, final JsonNode target, DiffOptions options) + public static JsonNode asJson(final JsonNode source, final JsonNode target, final DiffOptions options) { final String s; try { From 8f54df8312435a3898068829222cfff1a20b1e07 Mon Sep 17 00:00:00 2001 From: Alexandre Malbosc Date: Thu, 24 Sep 2020 15:43:06 +0200 Subject: [PATCH 5/5] https for repo.springsource.org --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 8ffa1a34..bae122d2 100644 --- a/build.gradle +++ b/build.gradle @@ -21,7 +21,7 @@ buildscript { repositories { mavenCentral() maven { - url "http://repo.springsource.org/plugins-release"; + url "https://repo.springsource.org/plugins-release"; } } dependencies {