Netflix / Netflix/dgs-codegen

Use explicit use‑site target annotations for @JsonProperty in generated Kotlin code

Open
#922 0 comments 0 reactions 1 assignee View on GitHub

@jiholee17 is already working on this.

Since Apr 6, 2026.

enhancement
Dominant language
Kotlin
Stars
217
Forks
116
PR merge metrics
No merged PRs in 30d

Description

When generating Kotlin classes with Kotlin 2.2+, each @JsonProperty annotation currently produces the following compiler warning:

w: file:///C:/git/dgs-sample/build/generated/sources/dgs-codegen/com/netflix/dgs/codegen/generated/types/SampleType.kt:14:3 This annotation is currently applied to the value parameter only, but in the future it will also be applied to field.

  • To opt in to applying to both value parameter and field, add '-Xannotation-default-target=param-property' to your compiler arguments.
  • To keep applying to the value parameter only, use the '@param:' annotation target.

See https://youtrack.jetbrains.com/issue/KT-73255 for more details.

Additional context is available here:
https://blog.jetbrains.com/idea/2025/09/improved-annotation-handling-in-kotlin-2-2-less-boilerplate-fewer-surprises/

To avoid these warnings and ensure consistent behavior across Kotlin versions, the code generator should use explicit use‑site targets. Instead of:

@JsonProperty("fieldName")

the generator should emit:

@field:JsonProperty("fieldName")

This explicitly applies the annotation to the field and matches the recommended approach for Kotlin 2.2+.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.