Answer the question
In order to leave comments, you need to log in
Is it possible to validate on an individual field of an object in Hibernate Validator?
Let me explain the essence of the issue. There is a DTO class with annotations for validation:
public class TagDto implements Serializable {
private Long id;
@NotBlank(message = PropertyKey.VALIDATION_TAG_NAME_NOT_EMPTY)
@Pattern(regexp = FieldRegexpValidator.TAG_NAME,
flags = Pattern.Flag.UNICODE_CASE,
message = PropertyKey.VALIDATION_TAG_NAME)
private String name;
}
public void method(@Valid TagDto tagDto) {...}.
String name
separately in another method, taking the validation from the TagDto
type like this:public void methodTwo(@Valid(from = TagDto.class, field = "name") String name) {...}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question