Skip to content

Question: Support type-use annotations for collection element validation (List<@Valid T>) #1770

@mcruzdev

Description

@mcruzdev

Hi folks, thanks a lot for this great project!

I have a question regarding Bean Validation annotations on generic type arguments (Java 8+ type-use annotations).

Current behavior

Given a JSON Schema that represents an array of objects, jsonschema2pojo generates:

@Valid
private List<TaskItem> _do = new ArrayList<>();

This places @Valid on the container (List) instead of on the type argument.

Expected / desired output

Ideally, the generated code would use a type-use annotation on the generic argument:

@Valid
private List<@Valid TaskItem> _do = new ArrayList<>();

(or even just List<@Valid TaskItem> depending on configuration)

This style is supported since Java 8 and is the recommended approach in Jakarta Bean Validation for expressing cascaded validation on collection elements.

Question

Is it possible (or planned) to support generating type-use annotations on generic type arguments? If not currently supported, would it be feasible to extend the API (e.g. via SchemaRule, Annotator, or another extension point) to enable this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions