Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions docs/json/kotlin.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion docs/json/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>()`; `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 |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}

Expand Down
Loading