Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom value extractor not found #449

Open
loicmathieu opened this issue Nov 4, 2024 · 2 comments
Open

Custom value extractor not found #449

loicmathieu opened this issue Nov 4, 2024 · 2 comments
Labels
help wanted Extra attention is needed info: good first issue Good for newcomers

Comments

@loicmathieu
Copy link

Expected Behavior

We should be able to create a custom value extractor and use it.

Actual Behaviour

Give the following value extractor

@Singleton
public class PropertyValueExtractor implements ValueExtractor<Property<@ExtractedValue ?>> {

    @Override
    public void extractValues(Property<?> originalValue, ValueReceiver receiver) {
        receiver.value( null, originalValue.getExpression());
    }
}

We should be able to use it to add validation annotations to the Property type parameter like that:

    @NotNull
    private Property<@Min(10) Integer> number;

But when we do that, it fails with the following error:

jakarta.validation.ConstraintDeclarationException: HV000197: No value extractor found for type parameter 'T' of type com.example.Property.
	at org.hibernate.validator.internal.metadata.core.MetaConstraints.addValueExtractorDescriptorForTypeArgumentLocation(MetaConstraints.java:147)
	at org.hibernate.validator.internal.metadata.core.MetaConstraints.create(MetaConstraints.java:63)
	at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.findTypeUseConstraints(AnnotationMetaDataProvider.java:806)
	at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.findTypeArgumentsConstraints(AnnotationMetaDataProvider.java:776)
	at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.findTypeAnnotationConstraints(AnnotationMetaDataProvider.java:609)
	at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.findPropertyMetaData(AnnotationMetaDataProvider.java:241)
	at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.getFieldMetaData(AnnotationMetaDataProvider.java:229)
	at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.retrieveBeanConfiguration(AnnotationMetaDataProvider.java:130)
	at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.getBeanConfiguration(AnnotationMetaDataProvider.java:121)
	at org.hibernate.validator.internal.metadata.BeanMetaDataManagerImpl.getBeanConfigurationForHierarchy(BeanMetaDataManagerImpl.java:234)
	at org.hibernate.validator.internal.metadata.BeanMetaDataManagerImpl.createBeanMetaData(BeanMetaDataManagerImpl.java:201)
	at org.hibernate.validator.internal.metadata.BeanMetaDataManagerImpl.getBeanMetaData(BeanMetaDataManagerImpl.java:165)
	at org.hibernate.validator.internal.engine.ValidatorImpl.buildNewLocalExecutionContext(ValidatorImpl.java:772)
	at org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedAnnotatedObjectForCurrentGroup(ValidatorImpl.java:627)
	at org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedConstraints(ValidatorImpl.java:590)
	at org.hibernate.validator.internal.engine.ValidatorImpl.validateParametersInContext(ValidatorImpl.java:880)
	at org.hibernate.validator.internal.engine.ValidatorImpl.validateParameters(ValidatorImpl.java:283)
	at org.hibernate.validator.internal.engine.ValidatorImpl.validateParameters(ValidatorImpl.java:235)
	at io.micronaut.validation.ValidatingInterceptor.intercept(ValidatingInterceptor.java:99)
	at io.micronaut.aop.chain.MethodInterceptorChain.proceed(MethodInterceptorChain.java:143)
	at com.example.$Example$Definition$Intercepted.post(Unknown Source)
	at com.example.$Example$Definition$Exec.dispatch(Unknown Source)

See the following reproducer, you can reproduce the error with the following curl command:

curl -XPOST --data '{"number": 42, "string": "Hello"}' -H "Content-Type: application/json" localhost:808

value-extractor.zip

You must use Micronaut validation 4.8.0 due to micronaut-projects/micronaut-validation#432

Steps To Reproduce

No response

Environment Information

Ubuntu 24.10
Java 21

Example Application

No response

Version

4.6.3

@graemerocher graemerocher added info: good first issue Good for newcomers help wanted Extra attention is needed labels Nov 7, 2024
@graemerocher
Copy link
Contributor

if you would like to contribute a PR to resolve this would be appreciated. In general Hibernate Validator support is in maintenance mode and we recommend users switch to Micronaut's implementation

@loicmathieu
Copy link
Author

I have no idea where to start, and if it would take long or not.

We may try to update to Micronaut's implementation but as I understand it, it's based on an annotation processor and as our plugins can contribute validators and we don't want too much dependencies between our plugins and Micronaut I'm not sure it will work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed info: good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants