I have created the following annotation to be used as part of a Spring MVC validation. Unfortunately, I'm getting the following exception:
Constraint annotation types must have at least one of the element types FIELD, METHOD, TYPE or ANNOTATION_TYPE as target.
Are annotations prohibited from using ElementType.PARAMETER
in the @Target
annotation?
package com.jason.app.service.control.validator;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import javax.validation.Constraint;
import javax.validation.Payload;
@Target(ElementType.PARAMETER)
//@Target({PARAMETER})
@Retention(RUNTIME)
@Documented
@Constraint(validatedBy = {ZipCodeValidator.class})
public @interface ZipCode {
String message() default "Must be a valid 5-digit zip code";
Class<?>[] groups() default { };
Class<? extends Payload>[] payload() default { };
}
Usage example of the annotation:
public ResponseBody<List<Order>> getOrdersByZipCode(@Valid @ZipCode String zipCode) {
// method body
}
Java version is Java 8.