Class ValidationBundle
- All Implemented Interfaces:
ru.vyarus.dropwizard.guice.module.installer.bundle.GuiceyBundle
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,
- Since:
- 26.12.2019
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidinitialize(ru.vyarus.dropwizard.guice.module.installer.bundle.GuiceyBootstrap bootstrap) voidrun(ru.vyarus.dropwizard.guice.module.installer.bundle.GuiceyEnvironment environment) By default, (Default) group is always added to groups defined withValidationGroupsannotation.targetClasses(com.google.inject.matcher.Matcher<? super Class> matcher) Customize target classes to apply validation on.targetMethods(com.google.inject.matcher.Matcher<? super Method> matcher) Customize target methods to apply validation on.Activates explicit mode, when onlyValidateOnExecutionannotated methods (or all methods in annotated class) are validated.validateAnnotatedOnly(Class<? extends Annotation> annotation) Same asvalidateAnnotatedOnly(), but you can specify custom annotation.Methods inherited from class ru.vyarus.dropwizard.guice.module.context.unique.item.UniqueGuiceyBundle
equals, hashCode
-
Constructor Details
-
ValidationBundle
public ValidationBundle()
-
-
Method Details
-
targetClasses
Customize target classes to apply validation on. By default, it would be all classes not annotated withPath.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).- Parameters:
matcher- matcher- Returns:
- bundle instance
-
targetMethods
Customize target methods to apply validation on. By default, all methods except annotated with rest annotations (GET, linkPOST, etc.) are allowed (seeRestMethodMatcher. 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 usevalidateAnnotatedOnly(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.- Parameters:
matcher- matcher- Returns:
- bundle instance
-
validateAnnotatedOnly
Activates explicit mode, when onlyValidateOnExecutionannotated methods (or all methods in annotated class) are validated.Shortcut for
ValidationModule.validateAnnotatedOnly().- Returns:
- bundle instance
-
validateAnnotatedOnly
Same asvalidateAnnotatedOnly(), but you can specify custom annotation.Shortcut for
ValidationModule.validateAnnotatedOnly(Class).- Parameters:
annotation- annotation to trigger validation- Returns:
- bundle instance
-
strictGroupsDeclaration
By default, (Default) group is always added to groups defined withValidationGroupsannotation.Calling this method disables default behavior: after calling it,
Defaultmust be explicitly declared.- Returns:
- bundle instance
-
initialize
public void initialize(ru.vyarus.dropwizard.guice.module.installer.bundle.GuiceyBootstrap bootstrap) -
run
public void run(ru.vyarus.dropwizard.guice.module.installer.bundle.GuiceyEnvironment environment) throws Exception - Throws:
Exception
-