spring-projects / spring-projects/spring-data-rest

PUT behaving like PATCH for nested collections [DATAREST-1012]

Open
#1,374 16 comments 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Dec 31, 2020.

in: repository status: feedback-provided type: bug
Dominant language
Java
Stars
958
Forks
568
PR merge metrics
No merged PRs in 30d

Description

Nick Ryan opened DATAREST-1012 and commented

With respect to the documentation at:

5.3. The item resource

it states for "PUT": Replaces the state of the target resource with the supplied request body.

When performing a PUT on a resource which contains a nested collection it invokes the method mergeForPut(...) in DomainObjectReader.java.

Based on the documentation I would expect:

PUT: the nested collection to be replaced rather than merged
PATCH: the nested collection to be merged

QUESTION 1: Is the documentation wrong, or the code wrong or am I misunderstanding the expected behaviour?

Secondary to this is the way this issue was encountered:

If we have a resource which contains a nested collection of polymorphic items:

e.g.

parent has a collection of child where each abstract child could be a concrete boy or girl

when POSTING to modify:

parent.children[0] = boy

to:

parent.children[0] = girl

the code ends up calling mergeForPut(...) and trying to modify a boy instance into a girl instance and I get a message like:

Target bean of type boy is not of type of the persistent entity (girl)!

QUESTION 2: What is the expected behaviour in this case or is this case not supported e.g. for a nested collection of abstract types it needs to be cleared before items of different concrete types are replaced?


Affects: 2.6 GA (Ingalls)

8 votes, 12 watchers

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.