gravity9-tech / json-patch-path

An RFC 6902 (JSON Patch) and reverse, plus RFC 7386 (JSON Merge Patch), implementation in Java using Jackson (2.x)
Other
11 stars 1 forks source link

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

Closed BartekGravity closed 1 year ago

BartekGravity commented 1 year ago

Issue copied from: https://github.com/java-json-tools/json-patch/issues/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.