I have a scenario where I need to validate some fields of a class depending on the value of a field from another class.
For ex: Street, City, Postal Code of Address class should not be null if the Employee has registered for a Group Retirement Plan.
Can this scenario be handled using Custom Validator of Hibernate Validator? Is this a good candidate for Hibernate Validator ? If so, could anyone provide me with some examples.
I have already gone through cross field validation examples like: Cross field validation with Hibernate Validator (JSR 303)
If I have a boolean indicator to indicate whether a user is registered for group retirement plan in Address domain class, I know I can come up with Custom Validator to verify the fields. But, I want to avoid adding indicator to Address class. As well, Address is not a field in Employee class to do nested validation.
The Frameworks I am using are Spring MVC and Mybatis for Data access. The validation is happening at Spring Rest API call with @Valid annotation.