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

[HV-1831] filters @Valid annotations from jvm and native types #1334

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

thst71
Copy link

@thst71 thst71 commented Nov 1, 2023

@thst71 thst71 marked this pull request as draft November 1, 2023 16:20
Comment on lines 1197 to 1199
return constrainable.getType().getTypeName().startsWith( "java." )
|| constrainable.getType().getTypeName().startsWith( "javax." )
|| constrainable.getType().getTypeName().matches( BUILTIN_TYPE_NAMES );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah ... I can see how it can be tempting to ignore these types 😃.
this probably will work for the primitives, but we cannot safely discard any classes. The user may define a model as:

class SomeClass {
    @Valid
    Object object;
}

which is a valid use case and the type of object field is checked at the runtime when SomeClass instance is passed for validation. So even if the class from these packages will not have any constraints, someone might extend the class and apply the constraints in that extended class...
Another problem is that even though these classes won't have any constraints declared as annotations, a user can always define a constraint through a programmatic DSL, or via XML...
That's why I'm leaning more towards this being a problem of the code generators that are adding redundant @Valid annotations ...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, good point. I thought about making this configurable, but I need to look at other config properties and how these are wired. I will remove the java check.

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