Search code examples
javavalidationdatespring-mvchibernate-validator

How to validate that date in future in reference to another date?


I have following bean:

class CampaignBeanDto {

    @Future
    Date startDate;

    Date endDate;

    ...
}

Obviously I that endDate should be after startDate. I want to validate it.

I know that I can manually realize annotation for @FutureAfterDate, validator for this and initialize threshold date manually but I want to use @Validated spring mvc annotation.

How can I achieve it?


Solution

  • You're gonna have to bear down and write yourself a Validator.

    This should get you started:

    Cross field validation with Hibernate Validator (JSR 303)