I couldn't find anything that helped so im asking:
I have two projects. Project A is the base project that defines basic stuff. Project B is a sub-project of Project A and extends its functionality (Project A should work like a framework and there will be further Projects C and D later). I have a domain object in Project A like:
public class BasePayload {
@CustomValidator
private String name;
}
The actual validation of the field 'name' should be in Project B, since all the sub-projects have different valid values for name. Also i would still like to also have a validator in Project A for testing purposes.
@Target({ ElementType.FIELD })
@Retention( RetentionPolicy.RUNTIME )
@Constraint(validatedBy = AbstractFieldValidator.class)
@Documented
public @interface CustomValidator{
String message() default "message";
Class<?>[] groups() default { };
Class<? extends Payload>[] payload() default { };
}
I tried defining my own annotation (@CustomValidator) and an abstract validator that has a implementation in Project B. But it doesn't quite work since one can not instantiate the abstract class. Once i have a implementation of that abstract validator in project A, the implementation in Project B is never used.
How would one design this? Is it possible at all? Thank you for your help.