I'm trying to setup a javax
Validation to compare two dates with each other.
One date should be less than the other.
Also, I created a custom constraint for both of my dates. But the problem is, that my annotation interface can't handle with non-primitive data types.
Here is my Code: (I know that this is wrong, but maybe you can understand my problem if I show my source)
Bean:
@DateValidator(firstDate="assignmentStart", secondDate="assignmentEnd")
public class ProjectAssignment implements IsSerializable {
private String id;
private Project project;
private String projectResponsibility;
private Date assignmentStart;
private Date assignmentEnd;
}
Annotation-Interface:
@Target({ TYPE, ANNOTATION_TYPE })
@Retention(RUNTIME)
@Constraint(validatedBy = DateValidatorImpl.class)
public @interface DateValidator {
String firstDate();
String secondDate();
String message() default "";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
}
So here is one Problem: I try to put the Date
type into the String
type.
But if I declare my firstDate
and secondDate
as a Date
, there is an issue:
Invalid type Date for the annotation attribute `DateValidator.firstDate;
only primitive type, `String`, `Class`, annotation, enumeration are permitted
or 1-dimensional arrays thereof
Are there any other ways to compare 2 Dates with each other?
What am I missing?