I have a question on JSR cross filed validation. I have a rest based service for get and post. So I have something like
@GET
ItemOfferId getItem(String)
other is that
@Post
boolean setItem(ItemOfferId)
In the ItemOfferId class I have class level annotation called @validoffer. So I have like this class
@validOffer
Class ItemOfferId{
OfferId offer;
ItemId item;
}
@Target({ ElementType.TYPE })
@Retention(RUNTIME)
@Documented
@Constraint(validatedBy = { OfferValidator.class })
public @interface ValidOffer {
String message() default "";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
}
public class Validator implements ConstraintValidator<ValidOffer,ItemOfferId>{
//i get here ItemOfferId object and do my custom validation
}
Now my question is that there are some constraints which are specific to " get " service and some are specific to "Set" service. The same object is used in both the methods for get and set. Is there any way to tell the annotation that it is get turn on the get validation. So basically I want to pass some parameters based on run time method call..?
Is it possible..? I have searched a lot in the Internet but could not find the answer... It would be really nice if I could find out how to solve this problem.
Thanks, Swati