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

JsonPatch and JsonUnwrapped property: PropertyReferenceException when patching fields in unwrapped path [DATAREST-1369]

Open
#1,702 0 comments 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Dec 31, 2020.

type: bug
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

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.