-
Notifications
You must be signed in to change notification settings - Fork 565
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HV-1942 Update DefaultGroupSequenceProvider add default method provide the class of instance #1310
base: main
Are you sure you want to change the base?
Conversation
Thanks for your pull request! This pull request does not follow the contribution rules. Could you have a look? ❌ All commit messages should start with a JIRA issue key matching pattern › This message was automatically generated. |
750077e
to
677982b
Compare
…e the class of instance
Hey @ilikly, thanks for submitting a pull request. Could you please provide a test case showing a problem you are trying to solve with these changes? But if you are trying to use |
But if the prodiver just return |
@ilikly please provide a sample project showing what you are trying to achieve and what doesn't work. It's hard to understand your requirement with the current details. Thanks! |
public class Test {
public static void main(String[] args) {
final ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory();
final Validator validator = validatorFactory.getValidator();
A a = new A();
validator.validate(a);
}
public static class GlobalDefaultGroupSequenceProvider implements DefaultGroupSequenceProvider<Object> {
@Override
public List<Class<?>> getValidationGroups(Object object) {
List<Class<?>> groups = new ArrayList<>();
if (object != null) {
groups.add(object.getClass());
}
return groups;
}
}
@Setter
@Getter
@GroupSequenceProvider(GlobalDefaultGroupSequenceProvider.class)
public static class A {
@NotNull
private String name;
}
@Setter
@Getter
@GroupSequenceProvider(GlobalDefaultGroupSequenceProvider.class)
public static class B {
@NotNull
private String name;
}
}
The parameter in callback of method |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm OK to incorporate this change but we need a test added.
Thanks!
engine/src/main/java/org/hibernate/validator/spi/group/DefaultGroupSequenceProvider.java
Outdated
Show resolved
Hide resolved
That being said, I'm not sure I understand when having a specific group sequence provider make sense if the bean class is actually null? I would expect it to not be validated and that having specific groups wouldn't make any difference? So if you contribute a test case, make sure I can see why it makes sense to actually have this feature. Thanks. |
I had add some test for DefaultGroupSequenceProvider. |
The provider can not get current class of instance when the instance is null When use a common DefaultGroupSequenceProvider for multi class. And the method of
BeanMetaDataImpl#getValidDefaultGroupSequence
checked must have the special group ofbeanClass.getName()
and also can not return the default group ofDefault.class
.