I am confused how to use @Valid annotation for Spring data rest.
I have entity class 'User'
@Entity
@Getter @Setter @ToString @NoArgsConstructor @AllArgsConstructor // from lombok
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Size(min = 8, max = 50)
private String email;
@Size(min = 8, max = 20)
private String password;
}
And 'UserRepository'
@RepositoryRestResource
public interface UserRepository extends JpaRepository<User, Integer> {
}
As I have used @Size annotation in entity(User).
But how to apply validation on api data i.e. how to use @Valid (to validate request body) as rest api ends are created by 'spring-data-rest'.