Skip to content

feat(kotlin): support runtime Kotlin JSON type tokens - #4054

Merged
chaokunyang merged 2 commits into
apache:mainfrom
chaokunyang:fix-kotlin-json-runtime-type
Sep 17, 2026
Merged

chaokunyang merged 2 commits into
apache:mainfrom
chaokunyang:fix-kotlin-json-runtime-type

Conversation

@chaokunyang

@chaokunyang chaokunyang commented Sep 17, 2026

Copy link
Copy Markdown
Collaborator

Framework callbacks cannot use a reified Kotlin type parameter, and wrapping their Java Type loses the Kotlin nullability needed to serialize generic responses such as Rt<List<Employee>>.

Add jsonTypeRef<T>(KType) using the existing structural type conversion, so callbacks can retain the controller's declared Kotlin type and pass it to Fory. The reified helper uses the same entry point. A dedicated integration guide introduces spring-fory and explains Kotlin runtime type discovery and Spring adapter requirements. kotlin-reflect remains an application dependency and is added only to tests here.

Fixes #4053.

Validation:

  • All 121 fory-json-kotlin tests passed with Kotlin 2.3.20 / JDK 21, including reflected generic roots, nested nullability, defaults, unsigned values, and incomplete type rejection.
  • Spotless and Markdown formatting passed.
  • The documented external-consumer example compiled and round-tripped successfully with Kotlin 2.4.10 / JDK 26.
  • No complete Spring application was run.

@ayush00git ayush00git left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chaokunyang
chaokunyang merged commit 180d6a7 into apache:main Sep 17, 2026
122 of 123 checks passed
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.

[Kotlin] ForyJsonException occurs when integrating ForyJsonKotlin with Spring

2 participants