I have the following Model Object:
@Validated
public class Message implements Serializable {
private static final long serialVersionUID = 9028633143475868839L;
@NonNull
@Size(min = 6, max = 6)
@Pattern(regexp = "[\\d]{6}")
private String id;
@NotNull
@Size(min = 1, max = 200)
private String title;
@NotNull
@Size(min = 1, max = 1000)
private String message;
@NotEmpty
private String type;
private String publishId;
public Message(){
}
public Message(@NonNull @Size(min = 6, max = 6) @Pattern(regexp = "[\\d]{6}") String id, @NotNull @Size(min = 1, max = 200) String title, @NotNull @Size(min = 1, max = 1000) String message, @NotEmpty String type, String publishId) {
this.id = id;
this.title = title;
this.message = message;
this.type = type;
this.publishId = publishId;
}
}
In this Message
class each field is annotated with validation constrains. Also whenever I auto generate constructor in IDEA IDE, annotations also auto attached in constructor parameters.
My question is: Is there any side effect if I remove these constrains either from constructor parameters or field/object property?
How internally those validation are working?
I'm using javax.validation.Validator::validate
for validation.
If possible please also attach link as reference