Java Validation - Adding @Valid constraint to custom constraint throws "@Valid is not applicable to annotation type" -


i have model object annotated java validation annotations.

class criteria{     @notempty string id;         @notempty string name;     string filename;     string hours;    } 

as per business requirement, either filename or hours field populated, validate have custom validator 'criteriavalidator' written.

@documented @constraint(validatedby = {criteriavalidator.class}) @retention(retentionpolicy.runtime) @target({elementtype.type , elementtype.field, elementtype.parameter}) public @interface validcriteria {     string message() default "{criteria.invalid}";     class<?>[] groups() default {};     class<? extends payload>[] payload() default {}; } 

the model above passed in input parameter method annotated @valid , @validcriteria.

public void update(@valid @validcriteria criteria criteria){...} 

the issue have 2 annotations in method. have add @valid in order check constraints annotated within class. custom validator checks existence of 1 of 2 fields: filename or hours.

the question have is, how have single annotation @validcriteria validates special requirement @notempty fields in object.

i tried adding @valid in custom constraint @validcriteria, error '@valid not applicable annotation type'

the @validcriteria annotation should on criteria class:

@validcriteria class criteria{     @notempty string id;         @notempty string name;     string filename;     string hours;    } 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -