2

Please let me know if spring validation and/or jsr hibernate validator has support.

I need to hookup bean validation in the controller , preferably using the @valid annotation of the parameter.

  1. In our beans I have properties with static constraints, such as range constraints etc.
  2. for some properties [say, id, name] I need conditional constraints, such as, if the request from the client is a 'create' , id should be null and name must not be empty. If the request is for update/delete I need the id to be not null and name is irrelevant.

For the static constraints, I have the spring+hibernate validator working fine. But, is there a way to achieve the conditional constraints?

Thank you

1

1 Answer 1

2

Using the @ConstraintValidator annotation this is possible, together with not putting any class level annotations in those two fields as those would apply all the time.

See here an example of an address constraint validator, and further info on the official doc.

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.