Skip to content

Replace linkable associations when merging existing array elements for merge patch - #2597

Open
ogawa-takeshi wants to merge 1 commit into
spring-projects:mainfrom
ogawa-takeshi:issue/2596
Open

Replace linkable associations when merging existing array elements for merge patch#2597
ogawa-takeshi wants to merge 1 commit into
spring-projects:mainfrom
ogawa-takeshi:issue/2596

Conversation

@ogawa-takeshi

Copy link
Copy Markdown

Closes #2596.

Since #2358, an object nested in an array is applied to the existing element at the same index via readPut(…) to obtain PUT semantics (RFC 7386). mergeForPut(…) skips linkable associations, which is intended for top-level PUT requests where associations are managed through association resources. Nested elements have no association resource, so the request body is the only place to express them. As a result, non-association properties of an existing element were updated while its associations kept their previous values, whereas appended elements and elements written into an empty collection resolved them properly.

This change

  • merges existing array elements through a dedicated path (mergeArrayElement) that forwards linkable associations to MergingPropertyHandler,

  • makes MergingPropertyHandler replace a linkable association with the reference contained in the payload instead of merging the source state into the referenced instance,

  • leaves the top-level PUT path (readPut / mergeForPut) unchanged,

  • adds patchReplacesReferenceOfEntityNestedInArray to DomainObjectReaderUnitTests (fails on main, passes with this change; handlesEntityNestedInAnArrayLikePutForPatchRequest from Nested arrays of entities need to get PUT semantics applied for merge patch #2358 keeps passing).

  • You have read the Spring Data contribution guidelines.

  • You use the code formatters provided here and have them applied to your changes. Don't submit any formatting related changes.

  • You submit test cases (unit or integration tests) that back your changes.

  • You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only).

…r merge patch.

Since spring-projects#2358, an object nested in an array is applied to the existing element at the same index via readPut(…) to obtain PUT semantics as defined by RFC 7386. mergeForPut(…) however skips linkable associations, which is intended for top-level PUT requests where associations are managed through association resources. Nested elements are not exposed as association resources, so the request body is the only place to express them. As a result, non-association properties of an existing element were updated while its associations kept their previous values, whereas appended elements and elements written into an empty collection resolved them properly.

We now merge existing array elements through a dedicated path that forwards linkable associations to the merging property handler, which replaces the reference with the one contained in the payload instead of merging the source state into the referenced instance.

Closes spring-projects#2596.

Signed-off-by: OGAWA, Takeshi <29126253+ogawa-takeshi@users.noreply.github.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Merge patch drops linkable associations of existing array elements since 4.3

2 participants