Reputation:
To reduce a chance of a bug. Or should I annotate only DTO? For example,
public class UserDto {
@NotNull
@NotEmpty
private String firstName;
@NotNull
@NotEmpty
private String lastName;
}
public class User extends AbstractBaseEntity {
@NotNull
@NotEmpty
private String username;
@NotNull
@NotEmpty
@Email
private String email;
}
P.S. Most of the code omitted for brevity
Upvotes: 1
Views: 407
Reputation: 15878
Yes it is completely ok to validate it on both.
Detailed : Spring Rest API validation should be in DTO or in entity?
Upvotes: 1