Skip to content

bugfix when handling array#97

Open
wenhoujx wants to merge 1 commit intojava-json-tools:masterfrom
wenhoujx:master
Open

bugfix when handling array#97
wenhoujx wants to merge 1 commit intojava-json-tools:masterfrom
wenhoujx:master

Conversation

@wenhoujx
Copy link

@wenhoujx wenhoujx commented Apr 6, 2021

there is a bug that all the operations in diffs are stateful in the sense that their operation depends on the operations before them.

The remove and add case breaks the diffs order b/c it removes and add to the end of diffs.

repro:

    @Test
    void testJsonPatchBug() throws JsonProcessingException, JsonPatchException {
        JsonNode config1 = YAML_MAPPER.readTree(""
                + "foo:\n"
                + "  - bar:\n"
                + "      - baz: a\n"
                + "      - baz: b\n"
                + "      - baz: c\n"
                + "  - bar:\n"
                + "      - baz: d\n");
        JsonNode config2 = YAML_MAPPER.readTree(""
                + "foo:\n"
                + "- bar:\n"
                + "  - baz: d\n"
                + "- bar:\n"
                + "  - baz: c\n"
                + "  - baz: b\n"
                + "  - baz: a\n");
        Assertions.assertThat(JsonDiff.asJsonPatch(config1, config2).apply(config1))
                .isEqualTo(config2);

    }

# test fails the actual config is : 
foo:
- bar:
  - baz: d
- bar:
  - baz: c
  - baz: c
  - baz: a

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

Successfully merging this pull request may close these issues.

1 participant