J
J
Jake Taylor2021-10-30 19:15:59
Hibernate
Jake Taylor, 2021-10-30 19:15:59

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;
}


To validate this DTO, you need to use the syntax public void method(@Valid TagDto tagDto) {...}.

And is it possible to validate a field String nameseparately in another method, taking the validation from the TagDtotype 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 question

Ask a Question

731 491 924 answers to any question