As I read fron documentation (https://spring.io/guides/gs/accessing-data-rest/)
PUT replaces an entire record. Fields not supplied will be replaced with null. PATCH can be used to update a subset of items.
So, I try to use PATCH for my User entity with 2 fields (name and surname)
@RequestMapping(path="/user/{id}", method = RequestMethod.PATCH)
public User updateUser ( User user) {
return userRepository.save(user);
}
When I send to:
localhost:8080/user/34
body with name: "user" and surname: "testSurname"
it works well.
but when I send only name (without surname)
, surname also updates to null.
How can I prevent spring boot from update fields with null values?