I am using spring rest data in my project and asking a query question
application/merge-patch+json. While the request application/json-patch+jsonworks well, I have problems with merge patch. For example, I have a nested object without a repository like this
"student":{
"id":1,
"address":{
"id":1,
"street":2,
"building":2
}
}
And I post PATCH, application/merge-patch+jsonin students/1
with this payload
{
"address":{
"street":3
}
}
I get this result
"student":{
"id":1,
"address":{
"id":2,
"street":3,
"building":null
}
}
So spring Data rest just created a new address object instead of merging.
Java code is like this
@Entity
@Table(name = "Student")
public class Student {
@Id
@GeneratedValue
private long studentId;
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "addressId")
private Address address;
}
Address Class:
@Entity
@Table(name = "Address")
public class Address {
@Id
@GeneratedValue
private long addressId;
private String street;
private String building;
}
Also, the student has a repository of rest and the address is not
My question is, how can I achieve the correct behavior when merging patch requests into spring data?
source
share