diff --git a/AGENTS.md b/AGENTS.md index 10f82994a0..3bea38ee9b 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -161,6 +161,10 @@ This is the entry point for AI guidance in Apache Fory. Read this file first, th `Object` quoted values remain strings. Quoted scalar common paths must parse directly from reader storage with no intermediate object allocation, reuse the unquoted token parser, and keep larger quoted handling in a separate cold method so native token parsing does not regress. +- Fory JSON Kotlin metadata-version compatibility belongs to + `KotlinClassMetadata.readStrict`. Do not add compiler or metadata minor-version allowlists after a + successful strict parse. Validate unsupported declaration shapes and mismatched JVM members at + the concrete consumer instead. - Decoder depth and the generic-type stack paired with that depth use root-operation failure cleanup. Nested decoders decrement depth and pop generic types only after successful child reads; do not add nested `try/finally` to restore them after exceptions. The root operation's `finally`/reset must clear both decoder depth and the generic-type stack. - Keep public APIs minimal. Public APIs must match user ownership and mental model, not internal implementation details; generated flows stay type-owned, while custom serializer registration stays explicit. - A Fory instance may register types or serializers only before its first root diff --git a/docs/json/kotlin.md b/docs/json/kotlin.md index feb7a320fc..0a6825f3c7 100644 --- a/docs/json/kotlin.md +++ b/docs/json/kotlin.md @@ -25,8 +25,8 @@ Fory JSON; it does not change Fory's binary protocols. ## Installation -The runtime supports Kotlin/JVM metadata ABI 2.3 and is built with Kotlin 2.3.20. Use the same Fory -version for every module: +The runtime accepts model metadata supported by Kotlin's strict metadata reader and is built with +Kotlin 2.3.20. Use the same Fory version for every module: ```kotlin title="build.gradle.kts" plugins { diff --git a/docs/json/troubleshooting.md b/docs/json/troubleshooting.md index 94839267c1..5d301fddf5 100644 --- a/docs/json/troubleshooting.md +++ b/docs/json/troubleshooting.md @@ -37,7 +37,7 @@ license: | | OutputStream write fails | The underlying `IOException` is wrapped as the cause of `ForyJsonException` | | Kotlin null or missing member fails | Check the exact `jsonTypeRef`, constructor default, and nullable occurrence; null does not request a compiler default | | Raw/star/projected Kotlin generic fails | Supply a complete `jsonTypeRef()`; `in` and star projections cannot reconstruct one exact schema | -| Unsupported Kotlin metadata | Compile the model with a supported Kotlin 2.3 compiler and ensure its validated JVM members match the metadata | +| Unsupported Kotlin metadata | Ensure the resolved `kotlin-metadata-jvm` supports the model compiler's metadata and that validated JVM members match it | | Kotlin model fails after Android shrinking | Apply KSP; for an exact Mixin, use it when either its source or target is Kotlin, and verify that the generated rules are packaged | | Kotlin model is absent in Native Image | Install `ForyJsonKotlin` from a reachable `ForyJsonProvider`, enable code generation, and make the exact binding reachable from that configuration | diff --git a/kotlin/fory-json-kotlin/src/main/kotlin/org/apache/fory/json/kotlin/KotlinMetadataModels.kt b/kotlin/fory-json-kotlin/src/main/kotlin/org/apache/fory/json/kotlin/KotlinMetadataModels.kt index b5a408ed79..be68e4738d 100644 --- a/kotlin/fory-json-kotlin/src/main/kotlin/org/apache/fory/json/kotlin/KotlinMetadataModels.kt +++ b/kotlin/fory-json-kotlin/src/main/kotlin/org/apache/fory/json/kotlin/KotlinMetadataModels.kt @@ -634,6 +634,8 @@ internal object KotlinMetadataTypes { ?: throw ForyJsonException("Unsupported Kotlin metadata on ${type.name}: missing @Metadata") val metadata = try { + // readStrict owns metadata-version compatibility. Callers validate the concrete Kotlin + // declaration and its matching JVM members instead of gating compiler minor versions. KotlinClassMetadata.readStrict(annotation) } catch (cause: IllegalArgumentException) { throw ForyJsonException("Unsupported Kotlin metadata on ${type.name}", cause) @@ -643,12 +645,6 @@ internal object KotlinMetadataTypes { "Unsupported Kotlin metadata on ${type.name}: not a class declaration", ) } - val version = metadata.version - if (version.major != 2 || version.minor != 3) { - throw ForyJsonException( - "Unsupported Kotlin metadata on ${type.name}: ABI $version; expected 2.3", - ) - } return metadata }