Skip to content

[FEATURE] Genrated Java Validation annotations on containers are deprecated #2647

Description

@javahippie

Why do we need this improvement?

Modelina offers support for generating javax.* and jakarta.* Validation annotations. Properties which are contained in collections / containers like java.util.List and java.util.Set are annotated like this:

@Valid
public List<MyClass> myClasses;

Unfortunately in newer versions of Java Bean validation, this causes a warning, as this behavior is deprecated:

HV000271: Using `@Valid` on a container (java.util.List) is deprecated. You should apply the annotation on the type argument(s)

The recommended style which is safe in the future would be to annotate the type parameter instead of the container:

public List<@Valid MyClass> myClasses;

How will this change help?

This change will allow Java projects using asyncapi code generation to generate Java classes which do not cause deprecation warnings.

Screenshots

No response

How could it be implemented/designed?

To not make this a breaking change, I would introduce a new property/flag to control this behavior. The "old" behavior would still be the default, and the new one could be enabled by setting a flag to true, similar to the useJakarta property. The CLI should be able to pass the property to modelina, so the feature is available both in the generator and the CLI

🚧 Breaking changes

No

👀 Have you checked for similar open issues?

  • I checked and didn't find a similar issue

🏢 Have you read the Contributing Guidelines?

Are you willing to work on this issue?

Yes I am willing to submit a PR!

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions