Skip to content

bugfix when handling array - #97

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

wenhoujx wants to merge 1 commit into
java-json-tools:masterfrom
wenhoujx:master

Conversation

@wenhoujx

@wenhoujx wenhoujx commented Apr 6, 2021 •

Copy link
Copy Markdown

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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant