For some reason if class have with some optional field and other regular field, valueContext for every field is using OptionalValueUnwrapper to unwrap and thowing cast exception since it is trying cst everyfield into option [ validator V validatedValue = (V) valueContext . isValid getCurrentValidatedValue ( validatedValue,constraintValidatorValue ) |https://github.com/hibernate/hibernate-validator/blob/e90fea5f5704b1b1f8c657a51fc2f9bde6f8380f/engine/src/main/java/org/hibernate/validator/internal/engine/constraintvalidation/ConstraintTree.java#L446]
public class KafkaProducerFactory extends KafkaClientFactory { static final int DEFAULT_BROKER_PORT = 9092; @NotNull @NotEmpty private String name; @NotEmpty private ImmutableSet<InetSocketAddress> bootstrapServers =of(); private Acknowledgement acknowledgement = ALL; @NotNull @UnwrapValidatedValue private Optional<CompressionType> compression = Optional.of(CompressionType.NONE);
}
I tired below code to validate Set<ConstraintViolation<T>> invalids = Validation.byProvider(HibernateValidator.class).configure().buildValidatorFactory().getValidator().validate(this);
and
Set<ConstraintViolation<T>> invalids = Validation.buildDefaultValidatorFactory().getValidator().validate(this); |
|