grails-core
grails-core copied to clipboard
Its not possible to register a custom constraint in Application.groovy unless its not @CompileStatic which it is by deafult
Expected Behavior
It should be possible to register a custom constraint (i.e. a class that implements Constraint) in a default web-app using e.g.:
// register constraints with domain class validator
JavaxValidatorRegistry registry = (JavaxValidatorRegistry)applicationContext.getBean(ValidatorRegistry)
registry.addConstraint(ExampleConstraint, [CharSequence])
// register constraint with @Validateable validator
DefaultConstraintEvaluator evaluator = (DefaultConstraintEvaluator)applicationContext.getBean(ConstraintsEvaluator)
evaluator.constraintRegistry.addConstraint ExampleConstraint
However evaluator.constraintRegistry fails because its a protected property of DefaultConstraintEvaluator
You have to remove the @CompileStatic from the Application class to get it to work
Either a means to register a customer constraint ought to be added to the ConstraintsEvaluator interface, or the constraintRegistry should be made pubic so it can be accessed from statically compiled code
Actual Behaviour
Its not possible to register a constraint unless you remove the @CompileStatic from the Application class
Steps To Reproduce
- grails create-app to create a baseline App
- Create a custom constraint, e.g. ExampleConstraint
- Attempt to register it in the Application class as above
Environment Information
No response
Example Application
No response
Version
5.1.2