ObjectMapper readerForUpdating to replace array

Viewed 1810

I have two different JSON files.

File A:

{
    "label": "A",
    "links": [
        {
            "url": "urla"
        }
    ]
}

File B:

{
    "links": [
        {
            "url": "urlb"
        }
    ]
}

Now I want to update A with the contents of B to get the following result JSON:

{
    "label": "A",
    "links": [
        {
            "url": "urlb"
        }
    ]
}

That is the links array should be fully replaced with the contents of B. But instead it merges the two Arrays:

{
    "label": "A",
    "links": [
        {
            "url": "urla",
            "url": "urlb"
        }
    ]
}

This is not desired. The code for the merged file:

JsonNode A = ... // resolved from a service call
JsonNode B = ... // resolved from a service call
ObjectMapper mapper = new ObjectMapper();
result = mapper.readerForUpdating(A).readValue(B);

I also tried to set mapper.setDefaultMergeable(false); but it didn't help.

I use com.fasterxml.jackson.core:jackson-core:jar:2.9.8

Can someone help me?

0 Answers
Related