In my Spring Boot application I have a following method:
Decision create(@NotBlank String name, String url, @NotNull User author);
Right now directly in the code I'm checking a following condition:
if (!org.apache.commons.lang3.StringUtils.isEmpty(url) && !urlValidator.isValid(url)) {
throw new IllegalArgumentException("Decision url is not valid");
}
In other word - url
parameter can be null
or a valid url.
Is it possible to replace this code with an existing validation annotation(for example JSR-303) ?