Support target: "type_use" for @annotate to avoid deprecated @Valid on containers (fixes #954) - #958
Open
harshit6392 wants to merge 2 commits into
Open
harshit6392 wants to merge 2 commits into
harshit6392 wants to merge 2 commits into
Conversation
harshit6392
requested review from
asibross,
iparadiso,
iuliiasobolevska,
jjacobs44,
kilink,
kzwang,
paulbakker and
srinivasankavitha
as code owners
September 16, 2026 14:04
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #954
Hibernate Validator 9.x / Jakarta EE 11 deprecates placing cascading-validation
annotations such as
@Validdirectly on a container type:and recommends annotating the type argument instead:
Today the
@annotatedirective'stargetoption only supports placing thegenerated annotation on the field/getter/setter/constructor-parameter
declaration (
target: "field" | "get" | "set" | "setparam" | "param"),so there was no way to reproduce the recommended
List<@Valid T>shape.What this PR does
Adds a new
target: "type_use"option for@annotate(Java codegen only).When used, the annotation is woven into the type itself (JSR‑308 /
type-use style) rather than added as a declaration annotation:
List<Employee>), the annotationis applied to the type argument:
List<@Valid Employee>.@NotNull String.The resulting type is applied consistently everywhere the field's type is
declared: the field itself, the getter return type, the setter parameter,
and the all-args constructor parameter.
Example
generates:
instead of the deprecated
@Valid List<EmployeeInput> employees.Changes
SiteTarget.kt— newTYPE_USEenum value.JavaPoetUtils.kt— newapplyTypeUseAnnotations(type, annotations)helperthat annotates a
ParameterizedTypeName's type argument(s), or the typeitself for non-parameterized types.
DataTypeGenerator.kt—addField,addGetterAndSetter, andaddParameterizedConstructornow recognizeSiteTarget.TYPE_USEand applythe annotation to the type via the new helper instead of as a declaration
annotation.
CodeGenTest.kt— two new tests covering the list/container case and theplain-type case.
Scope / follow-ups
Kotlin/Kotlin2 codegen (
KotlinPoetUtils.kt,Kotlin2*.kt) intentionallyisn't touched here — happy to add parity there in a follow-up if
maintainers want it before merging (CONTRIBUTING.md asks for feature
parity between the two).
@annotatedirective live in the separatenetflix.github.io/dgsdocs site, not in this repo, so they aren'tupdated as part of this PR.
Testing
Added
CodeGenTestcases:annotateOnTypesWithTargetsOnTypeUse annotates the list type argument instead of the containerannotateOnTypesWithTargetsOnTypeUse annotates a non-container field type directlyI wasn't able to run
./gradlew testin the environment I prepared thispatch in (no network access to Maven Central / Gradle's distribution
server), so please run the full test suite before merging — happy to fix up
anything that doesn't line up.