Skip to content

Instantly share code, notes, and snippets.

@kntmr
Created February 21, 2017 10:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kntmr/262611d8c7ab955889e15c50e45406f6 to your computer and use it in GitHub Desktop.
Save kntmr/262611d8c7ab955889e15c50e45406f6 to your computer and use it in GitHub Desktop.
Custom validator annotation
package sample;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.validation.Constraint;
import javax.validation.Payload;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@Constraint(validatedBy = { SampleValidator.class })
public @interface SampleValidation {
String param() default "";
String message() default "Validation Error";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment