| I have a POJO like below: @Value.Immutable public interface Customer { @NotBlank String name(); Optional<@Valid @NotNull(groups = Address.class) AddressDetails> addressDetails(); @Value.Immutable interface AddressDetails { @NotBlank String details(); } } And I have written a validator like this: private static Set<ConstraintViolation> validate(final Object object, final Class<?>... groups) { Set<ConstraintViolation> violations = new HashSet<>(); for (Method method : object.getClass().getInterfaces()[0].getDeclaredMethods()) { try { VALIDATOR.validateReturnValue( object, method, method.invoke(object), groups).forEach(constraint -> { ConstraintViolation constraintViolation = new ConstraintViolation( method.getName(), constraint.getMessageTemplate() ); violations.add(constraintViolation); } ); } catch (IllegalAccessException | InvocationTargetException e) { throw new IllegalStateException("daads", e); } } return violations; } When I pass the following Object of Customer in validate method above, `ImmutableCustomer.builder().name("test").addressDetails(ImmutableAddressDetails.builder().details("")).build` in object and group as `Address.class` I feel like it should return a violation as details field is empty and I marked it as NotBlank. But it does not fail. Any idea what I am doing wrong? |