[#271] Add an initialization context to the init method of the constraint validator#312
Conversation
…he constraint validator
yrodiere
left a comment
There was a problem hiding this comment.
I have nothing very useful to say, this makes sense.
Just a few comments to say I was useful :)
Also, does this require any change to the spec itself? I suspect it mentions the initialize method somewhere?
| * {@link #isValid(Object, ConstraintValidatorContext)} calls. | ||
| * The constraint annotation descriptor for a given constraint declaration is passed. | ||
| * <p> | ||
| * This method is guaranteed to be called before any use of this instance for validation. |
There was a problem hiding this comment.
The old initialize method also has this line... but it's wrong, because the old initialize method will no longer be called if the new one is overridden.
| * Validation providers are expected to call this method only. {@code ConstraintValidator}s should implement only one of the initialize methods. | ||
| * Either this one, which will be directly called by the validation provider, or the {@link #initialize(Annotation)}, | ||
| * which will be called through the default implementation of the current method. |
There was a problem hiding this comment.
This should be added to the javadoc of the other initialize method as well.
| * @return the provider for obtaining the current time, never {@code null}. If no | ||
| * specific provider has been configured during bootstrap, a default implementation using |
There was a problem hiding this comment.
You probably need to alter the Configuration classes to allow setting the provider? Unless that's already there for other purposes?
| * specific provider has been configured during bootstrap, a default implementation using | ||
| * the current system time and the current default time zone as returned by | ||
| * {@link Clock#systemDefaultZone()} will be returned. | ||
| */ |
There was a problem hiding this comment.
| */ | |
| * @since 4.0 | |
| */ |
| * | ||
| * @param constraintDescriptor annotation instance for a given constraint declaration | ||
| * @param context context in which the constraint is initialized | ||
| */ |
There was a problem hiding this comment.
| */ | |
| * @since 4.0 | |
| */ |
ConstraintValidatorInitializationContextto theConstraintValidator#initialize#271The idea here is that init method currently has no access to any extra context and should operate only based on the annotation information and we want to give the validators more input for initializtion steps. Validator providers can provide more context through their extension of the context (through
unwrap).I'm wondering whether we should deprecate the current
void initialize(A constraintAnnotation)or if we should keep it and rely on these default method impls .. ?opening as a draft for now as I'd like to see how others feel about the change.
cc: @yrodiere , @DavideD