micronaut-projects / micronaut-validation

Validation support for Micronaut
Apache License 2.0
6 stars 6 forks source link

Jakarta value extractors no longer working after migrating from Micronaut 3.x to 4.x #421

Closed Andrey-jpeg closed 3 weeks ago

Andrey-jpeg commented 3 weeks ago

Expected Behavior

Wrapped values can be validated by registering Jakarta value extractors.

Actual Behaviour

Objects cannot be deserialized or validated as the DefaultValidatorConfiguration cannot be instantiated.

Error instantiating bean of type  [io.micronaut.validation.validator.DefaultValidatorConfiguration]

Message: ValueExtractor definition 'com.github.andreyjpeg.SomeValueExtractor@54cc9ce8' is missing @ExtractedValue!
Path Taken: new $MaybeController$Definition$Intercepted(BeanResolutionContext $beanResolutionContext,BeanContext $beanContext,Qualifier $qualifier,List<BeanRegistration<Interceptor T> E> $interceptors,InterceptorRegistry $interceptorRegistry) --> new $MaybeController$Definition$Intercepted(BeanResolutionContext $beanResolutionContext,BeanContext $beanContext,Qualifier $qualifier,[List<BeanRegistration<Interceptor T> E> $interceptors],InterceptorRegistry $interceptorRegistry) --> new ValidatingInterceptor([Validator micronautValidator],ValidatorFactory validatorFactory,ConversionService conversionService) --> new DefaultValidator([ValidatorConfiguration configuration]) --> DefaultValidatorConfiguration.setValueExtractorRegistry([ValueExtractorRegistry valueExtractorRegistry])
io.micronaut.context.exceptions.BeanInstantiationException: Error instantiating bean of type  [io.micronaut.validation.validator.DefaultValidatorConfiguration]

Steps To Reproduce

run ValueExtractionTest.canSerailizetest in the example application

Environment Information

No response

Example Application

https://github.com/Andrey-jpeg/valueextraction

Version

4.6.3

dstepanov commented 3 weeks ago

V3 didn't support the value extractors. If you look at the KAPT mocks generated, you can see no annotation is present at the generic parameter. You could try using KSP.

Andrey-jpeg commented 3 weeks ago

But it was possible to get working with V3 - https://github.com/Nillerr/ksome

Whereas it doesn't work at all in V4

dstepanov commented 3 weeks ago

It looks like it was supported, and we took the first generic argument as the unwrapped value. I can try to allow it if the annotation is missing, will see if the TCK will pass

dstepanov commented 3 weeks ago

I have created a PR to allow it, but anyway your problem is with KAPT limitation, please consider switching to KSP