5

I am using the hibernate validator group sequence and want to execute the groups in a sequence based on business rules. But the input to the groupSequenceProvider for its getValidationGroups is always null, and hence custom sequence never gets added.

My request object:

@GroupSequenceProvider(BeanSequenceProvider.class)
public class MyBean {

    @NotEmpty
    private String name;

    @NotNull
    private MyType type;

    @NotEmpty(groups = Special.class)
    private String lastName;

    // Getters and setters        
}

Enum type:

public enum MyType {
    FIRST, SECOND
}

My custom sequence provider:

public class BeanSequenceProvider implements DefaultGroupSequenceProvider<MyBean> {

    @Override
    public List<Class<?>> getValidationGroups(MyBean object) {

        final List<Class<?>> classes = new ArrayList<>();
        classes.add(MyBean.class);
        if (object != null && object.getType() == MyType.SECOND) {
            classes.add(Special.class);
        }
        return classes;
    }
}

Group annotation:

public interface Special {
}

When I execute the above code, I get the input MyBean object as null and cannot add the custom sequence. What am I missing? I am using hibernate-validator version as 5.4.1.Final

buræquete
  • 14,226
  • 4
  • 44
  • 89
Mir
  • 139
  • 1
  • 6
  • Could you solve this issue? I am facing the same problem. I implemented the answer from here : https://stackoverflow.com/a/41849396/3238085 – user238607 Jul 17 '17 at 18:37
  • I think the problem has to do with differences between the type of validator we are invoking on the object `javax.validation.Validator` vs `org.springframework.validation.Validator` – user238607 Jul 17 '17 at 18:57
  • _"When I execute the above code"_ - How? Using `@Valid` annotation in controller? – user11153 Jul 18 '17 at 09:05

0 Answers0