Spring Bean validation giving ConstraintDeclarationException

Viewed 1292

I am getting javax.validation.ConstraintDeclarationException: HV000197: No value extractor found for type parameter 'T' of type reactor.core.publisher.Mono. I am getting this after adding @Validated at class level. If I remove this no validation logic triggers.

  @RestController
  @Validated
  public class ContactInfoController implements ContactInfoApi {
  public Flux<UserContactsModel> getUserContacts(@RequestBody  Mono<@Valid  LoginModel> loginDetail) {
1 Answers

The error message that you get is actually an expected behavior, as there's no ValueExtractor registered in HV. These value extractors are required by Bean Validation when the value should be extracted from some container. For more details on ValueExtractors please see this documentation

In your particular case Mono is treated as a container. But the concept of Mono (Subscriber) is not the same as a container. And I don't see how you could mix these two concepts together. To be able to "validate" a mono you would actually need to wrap its subscribe method with some validation proxy and perform the validation when a value is pushed to the mono itself.

Related