public class ValidationBundle
extends ru.vyarus.dropwizard.guice.module.context.unique.item.UniqueGuiceyBundle
Bundle registered automatically by bundles lookup. But if you want to configure it, simply register it directly (and lookup-provided instance would be ignored).
See ValidationModule for more info. Bundle essentially just provide shortcuts for module configurations.
Bundle also binds Validator and ExecutableValidator, so they become
available for injection. Custom validators may use guice injections.
WARNING: do not obtain validator directly from ValidatorFactory because it will not
be able to wire guice injections for validators requiring it. Module substitute Validator instance in
dropwizard Environment so custom guice-aware validators may be used on rest resources
too,
| Constructor and Description |
|---|
ValidationBundle() |
| Modifier and Type | Method and Description |
|---|---|
void |
initialize(ru.vyarus.dropwizard.guice.module.installer.bundle.GuiceyBootstrap bootstrap) |
void |
run(ru.vyarus.dropwizard.guice.module.installer.bundle.GuiceyEnvironment environment) |
ValidationBundle |
targetClasses(com.google.inject.matcher.Matcher<? super java.lang.Class> matcher)
Customize target classes to apply validation on.
|
ValidationBundle |
targetMethods(com.google.inject.matcher.Matcher<? super java.lang.reflect.Method> matcher)
Customize target methods to apply validation on.
|
ValidationBundle |
validateAnnotatedOnly()
Activates explicit mode, when only
ValidateOnExecution annotated methods (or all methods in
annotated class) are validated. |
ValidationBundle |
validateAnnotatedOnly(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
Same as
validateAnnotatedOnly(), but you can specify custom annotation. |
public ValidationBundle targetClasses(com.google.inject.matcher.Matcher<? super java.lang.Class> matcher)
Path.
If you declare your own target matcher, make sure it also avoids rest services:
yourMatcher.and(Matchers.not(Matchers.annotatedWith(Path.class))).
Shortcut for ValidationModule.targetClasses(Matcher).
matcher - matcherpublic ValidationBundle targetMethods(com.google.inject.matcher.Matcher<? super java.lang.reflect.Method> matcher)
GET, link POST, etc.) are allowed (see
RestMethodMatcher. Also, synthetic methods avoided.
It is better to also exclude synthetic and bridge methods from matching: you can simply add direct method
matcher: yourMatcher.and(new DirectMethodMatcher()).
Shortcut for ValidationModule.targetMethods(Matcher).
Note: it is possible to "implement" explicit mode with this matcher (like
Matchers.annotatedWith(MyAnn.class)), but better use validateAnnotatedOnly(Class).
Method call will produce correct log and eventually will extend your matcher with annotation condition.
But, if you want to implement exclusion annotation, then method matcher is the best choice:
Matchers.not(Matchers.annotatedWith(SuppressValidation.class)) will lead to validation
suppression on all annotated methods.
matcher - matcherpublic ValidationBundle validateAnnotatedOnly()
ValidateOnExecution annotated methods (or all methods in
annotated class) are validated.
Shortcut for ValidationModule.validateAnnotatedOnly().
public ValidationBundle validateAnnotatedOnly(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
validateAnnotatedOnly(), but you can specify custom annotation.
Shortcut for ValidationModule.validateAnnotatedOnly(Class).
annotation - annotation to trigger validationpublic void initialize(ru.vyarus.dropwizard.guice.module.installer.bundle.GuiceyBootstrap bootstrap)
public void run(ru.vyarus.dropwizard.guice.module.installer.bundle.GuiceyEnvironment environment)
throws java.lang.Exception
java.lang.Exception