GhostSerialization
1.2.3indexedHigh-performance, zero-reflection JSON serializer generating optimized zero-copy byte serializers via compile-time code generation; thread-safe registry, null-safety and memory/DoS safeguards, prewarm.
High-performance, zero-reflection JSON serializer generating optimized zero-copy byte serializers via compile-time code generation; thread-safe registry, null-safety and memory/DoS safeguards, prewarm.
Keep kotlinx.serialization (or Moshi / Gson / Jackson). Add one annotation on the DTO that hurts — same Ktor, Retrofit, or Spring stack.
Ghost is not a rewrite. It is the fast, low-allocation path for the models you opt in — and a softer landing when the backend ships messy JSON.
Quick Start — first DTO in minutes → · Try it in the browser → · Maven Central · Roadmap
Strict JSON fails the whole request. Ghost can keep going where you opt in:
{ "id": "u1", "name": "Ada", "age": { "years": 36 } }
@Serializable
@GhostSerialization
data class User(
val id: String,
val name: String,
@GhostResilient val age: Int = 0, // object instead of number → 0, parse continues
)
Unknown sealed variants → @GhostFallback. Opaque blobs → RawJson. Decode errors include a JSONPath (e.g. $.user.age) and, when useful, a fix hint in GhostJsonException / (JSON, Proto3 JSON, YAML cursor). Details →
Ghost generates only for @GhostSerialization — not for every @Serializable in the module.
@Serializable // keep — KotlinX call sites still work
@GhostSerialization // add — Ghost codegen for this class only
data class User(
@SerialName("user_id") // keep — Ghost uses this as the wire name
val id: Long,
val name: String,
)
Ghost.deserialize<User>(responseBytes) // Ghost (bytes / adapters)
@GhostName — optional if @SerialName is already set (GhostName wins only if both differ).@GhostResilient / @GhostFallback / RawJson — Ghost-only; omit if you don’t need them.@GhostSerialization too.Guides: Quick Start · Ktor · Android / Retrofit · Spring
Also: Android · iOS · JVM · Wasm (iOS/Wasm with no registration code, via the Gradle plugin) · YAML · Proto3 JSON · Kotlin 2.2.21+ / KSP 2.3.x / Ktor 3.3.x+ → Modules
On hot models Ghost is routinely several× faster and far leaner than KotlinX / Moshi. Most APIs are small — use it on the hotspot, not everywhere.
Twitter macro (631 KB) decode:

Benchmarks · HTTP Arena · Playground Speed Test
Run it yourself: ./gradlew :ghost-serialization:yamlComplianceMatrix · Details → YAML Conformance
Quick Start · · · · · · · · · · ·
| Drop-in |
|---|
| Ktor | ghost() next to json() · or bodyGhost / respondGhost |
| Retrofit | GhostConverterFactory before Gson / Moshi / KotlinX |
| Spring | ghost-spring-boot-starter — Ghost types via Ghost; Jackson for the rest |
| Ghost | KSER | Moshi |
|---|
| String | 1.2 GB/s · 308 KB | 0.72 GB/s · 1338 KB | 0.37 GB/s · 1709 KB |
| Bytes | 1.07 GB/s · 621 KB | 0.42 GB/s · 4297 KB | 0.28 GB/s · 4668 KB |
| Streaming | 0.53 GB/s · 1269 KB | 0.19 GB/s · 1905 KB | 0.43 GB/s · 1709 KB |
Surfaced from shared tags and platforms — no rankings paid for.