zjsonpatch
zjsonpatch copied to clipboard
FeatureRequest: Improve JsonDiff#compactDiffs by also considering replace
Expected Behavior
only move operations
[ {
"op" : "move",
"from" : "/0",
"path" : "/1"
}, {
"op" : "move",
"from" : "/2",
"path" : "/3"
} ]
Actual Behavior
1 remove, 1 replace, 1 add operation
[ {
"op" : "remove",
"path" : "/0",
"value" : "a"
}, {
"op" : "replace",
"path" : "/1",
"value" : "a"
}, {
"op" : "add",
"path" : "/3",
"value" : "c"
} ]
Steps to Reproduce the Problem
var expected = "[\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\"]";
var actual = "[\"b\",\"a\",\"d\",\"c\",\"e\",\"f\",\"g\",\"h\"]";
var diff = JsonDiff.asJson(Json.node(expected), Json.node(actual), EnumSet.of(DiffFlags.OMIT_COPY_OPERATION));
Specifications
Library Version: 0.4.4 Language (e.g. Java 1.8, Scala, etc): Java 11
I found this behavior while trying to understand and debug https://github.com/tomakehurst/wiremock/issues/1230
the same issue
As I understand, the way we compact transformations prioritizes replace
, move
and copy
respectively.
I will run some tests when I get some time, but I think it is possible to make an API where people can choose the "method" that they want to prioritize. Making some general rule would make Diffing more costly than it already is, and we still would not cover all people preferences, so I think the best course of action would be exposing a "compact order" API or something similar.