Apache Fory Kotlin adds Kotlin/JVM and Android support on top of the Fory Java runtime.
The Kotlin tree contains five Maven modules:
fory-kotlin: runtime integration for Kotlin/JVM and Android.fory-kotlin-ksp: KSP processor for Kotlin xlang/schema static serializers.fory-kotlin-tests: Java-driven Kotlin xlang test fixtures.fory-json-kotlin: Kotlin/JVM and Android integration for Fory JSON.fory-json-kotlin-ksp: KSP processor that emits exact R8/ProGuard retention rules for Fory JSON models and Mixins. It does not generate JSON codecs or source files.Add fory-kotlin when application code serializes Kotlin values:
implementation("org.apache.fory:fory-kotlin:<fory-version>")
Create Fory through the Kotlin module builder:
import org.apache.fory.kotlin.ForyKotlin data class User(val name: String, val id: UInt) val fory = ForyKotlin.builder() .withXlang(true) .requireClassRegistration(true) .build() fory.register(User::class.java)
fory-kotlin supports Kotlin-specific runtime types such as unsigned primitives, unsigned arrays, Kotlin collection carriers, default constructor values, kotlin.time.Duration, kotlin.text.Regex, and kotlin.uuid.Uuid. Use .withXlang(false) for same-language Kotlin/JVM native-mode payloads when you need JVM-native object behavior and Kotlin-specific type support without portable xlang type-mapping constraints.
Use fory-kotlin-ksp only for Kotlin classes that participate in Fory cross-language schema mode:
plugins { id("com.google.devtools.ksp") } dependencies { implementation("org.apache.fory:fory-kotlin:<fory-version>") ksp("org.apache.fory:fory-kotlin-ksp:<fory-version>") }
KSP generated serializers:
Application code should register target classes through the normal Fory Java APIs and should not reference generated serializer classes directly.
The Fory compiler can generate Kotlin source with --kotlin_out:
foryc schema.fdl --kotlin_out=src/main/kotlin
Generated Kotlin IDL models are Kotlin source only. Messages use data class by default, unions use sealed classes, and serializers are generated by fory-kotlin-ksp through the normal <Target>_ForySerializer discovery path. Use option kotlin_package = "..." to override the generated Kotlin package; otherwise Kotlin uses the FDL package. Registration still uses the FDL package for cross-language compatibility.
Android projects should use fory-kotlin for Kotlin runtime serializers and fory-kotlin-ksp for Kotlin xlang/schema structs. Validate Android behavior with a minified release build because debug builds do not prove R8 reachability.
See Kotlin Android Support for the Android setup and Kotlin Static Generated Serializers for the generated serializer model.
If an Android app also contains Java @ForyStruct classes, configure the Java annotation processor described in Java Static Generated Serializers.
Install the Java modules first, then build Kotlin:
cd ../java mvn -T16 install -DskipTests cd ../kotlin mvn clean package
Run Kotlin tests from this directory:
mvn test
Format Kotlin and Java sources:
mvn spotless:apply
Fory Kotlin targets Kotlin/JVM and Android. Kotlin/Native and Kotlin/JS are not supported.