I'm currently working on a small REST web service using spring-data-rest using :
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
I followed the following guide: https://spring.io/guides/gs/accessing-mongodb-data-rest/ and it's working really fine.
I add some annotation on my Person.class, in order to validate the object during a POST request (like @NonNull and so on) like this :
public class Person {
@Id
private String id;
@NonNull
private String firstName;
@NonNull
private String lastName;
private Integer age;
}
But now I want to do a PATCH request to update my object (by doing a request curl -X PATCH http://localhost:8080/people/598c2a80d8425fae64161cc4 -d '{"age":23}').
It's also working fine, but I want to prevent the update on some fields, people shouldn't be allowed to update firstName and lastName for example.
Is there some way to do it easily with an annotation? Or do I have to do a custom validation for every PATCH (or PUT) request? I don't like that solution because I would have to do it for every entity of my model.
I hope I clearly exposed my problem, if it's not clear, feel free to ask me more questions.
Thanks for your help.