我正在使用hibernate-validator - 4.2.0.Final lib for GroupSequenceProvider,它工作正常。
我已将我的应用程序升级到hibernate-validator - 5.2.4.Final并且我得到空指针异常。
我正在关注以下链接:
https://docs.jboss.org/hibernate/stable/validator/reference/en-US/html_single/?v=5.4#chapter-groups
以下是我的代码:
public class MyGroupSequenceProvider implements DefaultGroupSequenceProvider<CustomObject>
{
@Override
public List<Class<?>> getValidationGroups(CustomObject customObject)
{
List<Class<?>> defaultGroupSequence = new ArrayList<Class<?>>();
defaultGroupSequence.add(CustomObject.class);
if (customObject.getType().equals("Number") {
defaultGroupSequence.add(NumberChecks.class);
}
else if (customObject.getType().equals("String")) {
defaultGroupSequence.add(StringChecks.class);
}
return defaultGroupSequence;
}
}
此外,
下面是我的模型类:
@AllArgsConstructor
@Getter
@GroupSequenceProvider(MyGroupSequenceProvider.class)
public class CustomObject {
@NotNull
private String type;
@Length(min = 2, max = 4,groups = NumberChecks.class)
@Length(min = 2, max = 7, groups = StringChecks.class)
private String value;
}
由于