spring-projects / spring-projects/spring-data-rest
PUT/PATCH operation sets embedded values to null when using @JsonUnwrapped [DATAREST-737]
@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
Clemens Keppler opened DATAREST-737 and commented
Hi,
while having an embedded object (e.g. "Address"), updating the object which embeds that object (e.g. "Person") via PATCH/PUT will result in a null value for the embedded object (e.g. "Address") when @JsonUnwrapped is used for the embedded object.
Steps for reproducing:
@Entity
public class Person {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
private String firstName;
@Embedded
@JsonUnwrapped
private Address address;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
}
@Embeddable
public class Address {
private String city;
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
}
With the usual repository for Person.class and the usual application class.
The query
curl -X POST --data '{"firstName":"Testi", "city":"TestCity"}' -H "Content-Type:application/JSON" http://localhost:8080/person
Followed by
curl -X PATCH --data '{"firstName":"Testi v2"}' -H "Content-Type:application/JSON" http://localhost:8080/person/3
Will result in the field city being null.
Removing the @JsonUnwrapped and using following queries will work as intended though.
curl -X POST --data '{"firstName":"Testi", "address":{"city":"TestCity"}}' -H "Content-Type:application/JSON" http://localhost:8080/person
curl -X PATCH --data '{"firstName":"Testi v2"}' -H "Content-Type:application/JSON" http://localhost:8080/person/1
3 votes, 4 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.