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

Micronaut 4 is unable to validate classes from another module #236

Open
sergey-morenets opened this issue Oct 19, 2023 · 0 comments
Open

Comments

@sergey-morenets
Copy link

Expected Behavior

Micronaut 4 should apply validation annotations even if class is in another module(jar).

Actual Behaviour

Hi

We tried to migrate Micronaut 3 project to Micronaut 4 however our tests started failing because validation stopped working.
After detailed investigation it turned out that Micronaut 4 doesn't apply validation annotation on the classes that come from another jar. For example:

@Getter
@Setter
public class Product {

    @NotEmpty
    @Size(
            min = 3,
            max = 16
    )
    private String name;

    private int id;
}

We can't put @introspected annotation there so we use another approach:


@Introspected(classes = Product.class)
public class BeanValidationConfiguration {
}

We debugged this behavior to the method in AnnotationMetadataSupport:

    @Internal
    static void registerRepeatableAnnotation(@NonNull String repeatable, @NonNull String repeatableContainer) {
        REPEATABLE_ANNOTATIONS_CONTAINERS.put(repeatable, repeatableContainer);
    }

It seems that REPEATABLE_ANNOTATIONS_CONTAINERS map contains only those annotations that are found inside current module.
So to workaround that we need to create dummy class and put there @notempty and @SiZe annotations.

Steps To Reproduce

No response

Environment Information

JDK 21

Example Application

No response

Version

4.1.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant