Skip to content

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

Open
@gabrielsson

Description

@gabrielsson

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions