use of javax.validation.groups.Default in project dropwizard by dropwizard.
the class DropwizardConfiguredValidator method getGroup.
/**
* If the request entity is annotated with {@link Validated} then run
* validations in the specified constraint group else validate with the
* {@link Default} group
*/
private Class<?>[] getGroup(Invocable invocable) {
final ImmutableList.Builder<Class<?>[]> builder = ImmutableList.builder();
for (Parameter parameter : invocable.getParameters()) {
if (parameter.isAnnotationPresent(Validated.class)) {
builder.add(parameter.getAnnotation(Validated.class).value());
}
}
final ImmutableList<Class<?>[]> groups = builder.build();
switch(groups.size()) {
// No parameters were annotated with Validated, so validate under the default group
case 0:
return new Class<?>[] { Default.class };
// A single parameter was annotated with Validated, so use their group
case 1:
return groups.get(0);
// group.
default:
for (int i = 0; i < groups.size(); i++) {
for (int j = i; j < groups.size(); j++) {
if (!Arrays.deepEquals(groups.get(i), groups.get(j))) {
throw new WebApplicationException("Parameters must have the same validation groups in " + invocable.getHandlingMethod().getName(), 500);
}
}
}
return groups.get(0);
}
}
Aggregations