Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FeatureRequest: Improve JsonDiff#compactDiffs by also considering replace #113

Open
pjungermann opened this issue Nov 29, 2019 · 2 comments

Comments

@pjungermann
Copy link

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

@pjungermann pjungermann changed the title Improve JsonDiff#compactDiffs by also considering replace FeatureRequest: Improve JsonDiff#compactDiffs by also considering replace Nov 29, 2019
@aantoniuk-gl
Copy link

the same issue

@LouizFC
Copy link
Collaborator

LouizFC commented Dec 7, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants