Skip to content

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

Description

@daniel-morgenstern

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+.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Fields

No fields configured for Feature.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions