-
Notifications
You must be signed in to change notification settings - Fork 564
The merge+patch implementation does not support merging arrays nested within a map #2350
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
Comments
Can you provide a reproducer for that? I've just tried a unit tests on @Test
void replacesNestedArrays() throws Exception {
MapWrapper wrapper = new MapWrapper();
wrapper.map.put("array", new String[] { "original" });
ObjectMapper mapper = new ObjectMapper();
JsonNode node = mapper.readTree("{ \"map\" : { \"array\" : [ \"first\", \"update\" ] } }");
MapWrapper result = reader.doMerge((ObjectNode) node, wrapper, mapper);
node = mapper.readTree("{ \"map\" : { \"array\" : [ \"second\", \"update\" ] } }");
result = reader.doMerge((ObjectNode) node, wrapper, mapper);
System.out.println(result.map.get("array"));
}
static class MapWrapper {
public Map<String, Object> map = new HashMap<>();
} And it shows the second update being applied properly. Also, merge patch requires arrays to be replaced entirely according to the RFC:
|
Assuming you're running DomainObjectReaderUnitTests just add the persistent entity to reproduce it:
It's very important because it jumps into loop while in your case it simply stops here:
|
I can reproduce the problem now. Thanks for the additional hint! 🙇 |
This is fixed on main and backported to 4.2.x and 4.1.x. Feel free to give the snapshots a try. |
Hello @odrotbohm the fix doesn't work on my use case. I tried it with version 4.2.3-SNAPSHOT but still have the issue. |
I'm going to keep this one closed, as it's specifically about array handling in maps. That said, I've filed #2357. |
Assume an entity mapped like that (using hibernate-types-60 library for JsonType):
When a first PATCH request is executed for the entity with the following request body:
Then, correct JSON is stored in a database.
However, on all subsequent PATCH requests it's simply impossible to update this nested array property. E.g. the following call:
does not make any effect.
The expected behavior is to have an ability to overwrite nested array fields. Currently the only possible way to accomplish that is to make 2 calls - 1st to set the array back to null (this works as DomainObjectReader does not even try to merge and simply replaces the value. And 2nd to set the array to the desired value.
Thanks in advance.
The text was updated successfully, but these errors were encountered: