0
public class MyDomain {
    String test;

    @NotBlank
    @Pattern(regexp = "[0-9]")
    public String getTest() {
        return this.test;
    }
}

I've written a commons library with default validation: the test string should never be blank.

But in one application I want to explicit allow blanks here for this parameter.

Question: how can I make the @Pattern validation conditional, eg based on a application.properties value?

1 Answer 1

1

You could implement a custom validator for @NotBlank which takes the setting from application.properties into account.

When configuring this validator, e.g. through an XML constraint mapping file, you'd have to disable the default validator for the constraint, letting only your new implementation take over.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.