I'm working on my first project with Spring and Hibernate and I would like to create a validator for an IP address.
To create the project I use IntelliJ. When I enter the code like this I get an error on the @Target
annotation Attribute value must be a class literal
I do understand what this annotation has to do, but if I keep getting this error, it won't work.
I have looked at the documentation about custom constraints here http://docs.jboss.org/hibernate/validator/5.0/reference/en-US/html_single/#validator-customconstraints-simple and I have looked at several Stackoverflow pages, but I can't get this error solved.
import org.hibernate.annotations.Target;
import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import static java.lang.annotation.ElementType.FIELD;
/**
* Created by johan on 17-5-17.
*/
@Target({ FIELD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Constraint(validatedBy = IpAddressValidator.class)
public @interface IpAddress{
String message() default "{ipAddress.invalid}";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
}
What do I need to do to get this working?
FIELD.class
? – litelite May 17 '17 at 17:30Unknown class: FIELD
– Johan Vergeer May 17 '17 at 17:36FIELD
is a global constant, not a class. – litelite May 17 '17 at 17:40