Skip to content

Add support for type-use annotations (TYPE_USE target) (JSR 308, Java 8+)#127

Merged
phax merged 1 commit intophax:masterfrom
joelittlejohn:type-annotation-targets
Feb 3, 2026
Merged

Add support for type-use annotations (TYPE_USE target) (JSR 308, Java 8+)#127
phax merged 1 commit intophax:masterfrom
joelittlejohn:type-annotation-targets

Conversation

@joelittlejohn
Copy link
Copy Markdown
Contributor

Adds JAnnotatedClass which wraps an AbstractJClass with type-use annotations, enabling code generation like List<@Valid Item>.

Usage:
AbstractJClass annotatedItem = itemClass.annotated(Valid.class);
AbstractJClass listType = cm.ref(List.class).narrow(annotatedItem);

Addresses #50

… 8+)

Adds JAnnotatedClass which wraps an AbstractJClass with type-use
annotations, enabling code generation like List<@Valid Item>.

Usage:
  AbstractJClass annotatedItem = itemClass.annotated(Valid.class);
  AbstractJClass listType = cm.ref(List.class).narrow(annotatedItem);

Addresses phax#50
@joelittlejohn
Copy link
Copy Markdown
Contributor Author

I've gone a different route here than the one suggested in #50, because this allows us to avoid a breaking change.

I haven't managed to come up with a better name than annotated, but it's very similar to the pre-existing annotate that is used on class declarations. I've tried to make it clear what the difference is in the javadoc. Happy to rename this if needed.

This problem came up for me in jsonschema2pojo, because using javax/jakarta's @Valid annotation for arrays and other collections is now supposed to go onto the item type, not onto the container field. More info in joelittlejohn/jsonschema2pojo#1770 and serverlessworkflow/sdk-java#1123.

@ricardozanini
Copy link
Copy Markdown

Thank you!

@phax phax merged commit 416cd58 into phax:master Feb 3, 2026
1 check passed
@phax
Copy link
Copy Markdown
Owner

phax commented Feb 3, 2026

@joelittlejohn thanks a lot for your effort - really appreciate it.

Do you have anything more in the pipeline or can I start preparing the 4.2.0 release?

@joelittlejohn
Copy link
Copy Markdown
Contributor Author

@phax Great stuff! I want to add another change here to support params in these type annotations. This will be arriving today and I'll open a new PR.

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

Successfully merging this pull request may close these issues.

3 participants