spring-projects / spring-projects/spring-data-rest
PATCH overrides ReadOnlyProperty [DATAREST-1144]
@odrotbohm is already working on this.
Since Dec 31, 2020.
- Dominant language
- Java
- Stars
- 958
- Forks
- 568
- PR merge metrics
- No merged PRs in 30d
Description
Michael S opened DATAREST-1144 and commented
PATCHing overrides a read-only property, PUTting doesn't.
E.g. using the following entity:
@Entity
public class Person {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
private String firstName;
private String lastName;
@ReadOnlyProperty
private String place;
// snip
}
The property "place" gets set internally using
@HandleBeforeCreate
public void handleBeforeCreate(Person person) {
if(person.getPlace() == null) {
person.setPlace("The Shire");
}
}
A PUT call using e.g. a json payload like the following results in an unchanged place:
{ "firstName" : "Frodo", "lastName" :"Baggins", "place" : "Mordor" }
However PATCHing the same (or a partial) payload changes the place to the new value.
Please see the referenced quickstart that reproduces the problem.
I dug a bit into the issue and found out that during a PATCH request JsonPatchHandler calls DomainObjectMerger's read that omits the property checking whereas PUT calls readPut that does the property checks.
Note that this should also work using
@JsonProperty(access = Access.READ_ONLY)
but this isn't tested in the referenced project since a bug (DATAREST-1006 got fixed some hours ago) is responsible for also overrides on PUT
Affects: 2.6.7 (Ingalls SR7)
Reference URL: https://github.com/msparer/gs-accessing-data-rest
1 votes, 3 watchers
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.