kotlin.md

August 16, 2026 ยท View on GitHub

Fory Kotlin provides binary Object Serialization, generated models, Fory gRPC, and Android support. It runs on Fory Java and supports Java 8 and later.

Verify the Toolchain

java -version
./gradlew --version
# or: mvn -version

Object Serialization

Add the Fory Kotlin library to the application module:

dependencies {
  implementation("org.apache.fory:fory-kotlin:1.6.1")
}

Create src/main/kotlin/KotlinExample.kt:

import org.apache.fory.ThreadSafeFory
import org.apache.fory.kotlin.ForyKotlin

data class User(val id: Long, val name: String)

fun main() {
    val fory: ThreadSafeFory = ForyKotlin.builder()
        .withXlang(true)
        .requireClassRegistration(true)
        .buildThreadSafeFory()
    fory.register(User::class.java, 1)

    val bytes = fory.serialize(User(1, "Alice"))
    val decoded = fory.deserialize(bytes) as User
    println(decoded.name)
}

If the project applies Gradle's application plugin, run its application task:

./gradlew run

Use xlang mode when a peer uses a different Fory implementation family; use native mode for data within the JVM Fory implementation family. Continue with Kotlin Object Serialization, xlang, or native mode.

Other Capabilities