Skip to content

There is no possibility to set jsonNodeFactory when working with patches. #42

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

Closed
BartekGravity opened this issue Jun 29, 2023 · 0 comments · Fixed by #43
Closed

There is no possibility to set jsonNodeFactory when working with patches. #42

BartekGravity opened this issue Jun 29, 2023 · 0 comments · Fixed by #43
Assignees

Comments

@BartekGravity
Copy link

Issue copied from: java-json-tools#110

I would like to use the library withExactBigDecimals, i.e keeping 25.000 when patching a node.

@Test
void testDecimalsKeptAfterPatch() {

    ObjectMapper mapper = new ObjectMapper()
        .enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS)
        .setNodeFactory(JsonNodeFactory.withExactBigDecimals(true));

    JsonNode newer = mapper.readTree("25.000");
    JsonNode older = mapper.readTree("24.444");
    JsonNode apply = JsonMergePatch.fromJson(newer).apply(older);

    assertEquals("25.000", apply.asText());
}
org.junit.ComparisonFailure: expected:<25[.000]but was:<25[]>
Expected :25.000
Actual   :25

Is it possible to inject the behaviour I am after? The JacksonUtils that JsonMergePatch is using sets the factory to JsonNodeFactory.instance and I cannot see a way around this. I would prefer to use the JsonNodeFactory.decimalsAsIs for my specific case.

This also applies to the JsonDiff.asJson(older, newer) with the same behaviour as the above example.

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