spring-projects / spring-projects/spring-data-rest
JsonPatch and JsonUnwrapped property: PropertyReferenceException when patching fields in unwrapped path [DATAREST-1369]
@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
genglefr opened DATAREST-1369 and commented
I'm using Spring Boot 2.2.0 M2, and I'm building an application on top of Spring Data Rest.
I'm experiencing an issue when using JSON Patch Content-Type = application/json-patch+json in combination with @JsonUnwrapped properties.
Let's consider I have a Person entity, with a @JsonUnwrapped data property that holds a String name field.
I'd like to patch this entity via:
curl -X PATCH --data '[{"op":"replace", "path":"/name", "value":"test patch"}]' -H "Content-Type:application/json-patch+json" http://localhost:8080/person/1
Unfortunately, this raises an exception:
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property name found for type Person!
at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:94) ~[spring-data-commons-2.2.0.M3.jar:2.2.0.M3]
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:382) ~[spring-data-commons-2.2.0.M3.jar:2.2.0.M3]
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:358) ~[spring-data-commons-2.2.0.M3.jar:2.2.0.M3]
at org.springframework.data.mapping.PropertyPath.lambda$from$0(PropertyPath.java:311) ~[spring-data-commons-2.2.0.M3.jar:2.2.0.M3]
at java.base/java.util.concurrent.ConcurrentMap.computeIfAbsent(ConcurrentMap.java:330) ~[na:na]
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:293) ~[spring-data-commons-2.2.0.M3.jar:2.2.0.M3]
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:276) ~[spring-data-commons-2.2.0.M3.jar:2.2.0.M3]
Instead, if I specify my @JsonUnwrapped property in the path of the patch request, it works like a charm:
curl -X PATCH --data '[{"op":"replace", "path":"/data/name", "value":"test patch"}]' -H "Content-Type:application/json-patch+json" http://localhost:8080/person/1
According to me, @JsonUnwrapped properties should be automatically considered when evaluating paths of patch requests
Affects: 3.2 M3 (Moore)
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.