Hello, I have a container class defined like so:
public sealed interface Either<L,R> {
record Left<L, R>(L value) implements Either<L, R> {}
record Right<L, R>(R value) implements Either<L, R> {}
}
also I wrote a required ValueExtractor
public class RightValueExtractor<L, R> implements ValueExtractor<Either<L, @ExtractedValue R>> {
@Override
public void extractValues(Either<L, R> either, ValueReceiver valueReceiver) {
switch(either) {
case Either.Right<L, R> right -> valueReceiver.value(null, right.value());
default -> throw new IllegalStateException("Unexpected value: " + either);
}
}
}
// LeftValueExtractor implemented likewise
and mentioned it in the services file appropriately (meaning ide does not complain)
But when I'm trying to validate the value inside of Either with a following sample
@AllArgsConstructor
class ValidationTesting {
private final Either<Ignore, @Email String> email;
}
...
ValidationTesting email = new ValidationTesting(new Either.Left(Ignore.IGNORE));
Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
assertEquals("Validation: ", 0, validator.validate(email).size());
i get this error:
jakarta.validation.ConstraintDeclarationException: HV000197: No value extractor found for type parameter 'R' of type com.example.Either.
What is wrong here? Is there something that I'm missing?