
Byte-first, compile-time JSON serializer generating zero-allocation codecs with bitwise O(1) trie field matching, required-field bitmask checks, dedicated readers and thread-local pools for high-throughput, low-memory endpoints.
Parse and hydrate Kotlin models at up to 1.2 GB/s — drop in beside the serializer you already use.
Ghost sits beside kotlinx.serialization, Jackson, Gson, or Moshi. Annotate only the hot DTOs, leave everything else alone, and migrate when you want.
Quick Start · Maven Central · Live Ghost Speedtest · Playground · Benchmarks · Coverage · Roadmap
You already have a JSON stack. Ghost is the optimization layer for the endpoints and models that show up in profiles:
ByteArray and Okio streams without String round-trips@GhostSerialization
data class User(val id: Long, val name: String, val email: String)
val user: User = Ghost.deserialize(responseBytes) // hot path
val json: String = Ghost.encodeToString(user)Your other models keep using KotlinX, Jackson, Gson, or Moshi — unchanged.
Twitter macro fixture (631 KB). Three views of the same decode run — throughput ↑, latency ↓, memory ↓:
| Ghost | KSER | Moshi | Ghost vs slowest | |
|---|---|---|---|---|
| Decode string | 1.2 GB/s · 514 µs · 361 KB | 0.718 GB/s · 879 µs · 1338 KB | 0.374 GB/s · 1688 µs · 1709 KB | ~3.3× faster · 79% less memory |
| Decode bytes | 1.05 GB/s · 600 µs · 621 KB | 0.424 GB/s · 1489 µs · 4297 KB | 0.275 GB/s · 2297 µs · 4668 KB | ~3.8× faster · 87% less memory |
| Decode streaming | 0.53 GB/s · 1194 µs · 1269 KB | 0.193 GB/s · 3270 µs · 1905 KB | 0.426 GB/s · 1482 µs · 1709 KB | ~2.7× faster · 33% less memory |
Full tables + how to run them → Benchmarks · also ktor-ghost on HTTP Arena (+14% vs plain Ktor).
Host:
./gradlew :ghost-benchmark:benchmarkTwitter -PskipTests(full profile, 10 000-iteration warmup) on Ubuntu 24.04 (Linux x86_64) · AMD Ryzen 9 7900X (12 cores / 24 threads, up to ~5.7 GHz boost) · 64 GB RAM · Eclipse Temurin JDK 17 (GradlejvmToolchain(17)) · Kotlin 2.4.0. Absolute GB/s varies by machine; relative Ghost vs KSER/Moshi rankings are what the regression gate tracks.
| Stack | How Ghost fits |
|---|---|
| Ktor |
ghost() beside json() — Ghost DTOs first, KotlinX for the rest |
| Retrofit |
GhostConverterFactory before Gson / Moshi / KotlinX |
| Spring Boot | starter routes @GhostSerialization DTOs; Jackson keeps everything else |
| Direct calls | only the call sites you profile |
Step-by-step → Quick Start
| Targets | |
|---|---|
| Published (Maven Central 1.3.0) | Android · iOS · JVM · Wasm (wasmJs) |
| Toolchain | Kotlin 2.4.0 · KSP 2.3.10 · Ktor 3.5.x |
Also: Retrofit 2.11+, Spring Boot 3.4+ (MVC + WebFlux), YAML (application/yaml), Proto3 JSON mapping.
Details → Modules
| Guide | What you'll find |
|---|---|
| Quick Start | First DTO in minutes |
| Installation | Catalog, KSP, opt-outs |
| Android & Retrofit | Apps, OkHttp, converters |
| KMP & Ktor | Shared module + client/server |
| iOS & Swift | XCFramework bridge |
| Spring Boot | MVC / WebFlux + Jackson |
| YAML |
decodeFromYaml, Ktor/Spring/Retrofit adapters |
| Proto3 JSON | WKTs and mapping rules |
| Advanced Features | Resilience, flatten, RawJson |
| Architecture | Prediction, SWAR, hashed dispatch, pools |
| Roadmap | OpenAPI codegen, tests, badges |
| Contributing | Tests and PR checklist |
git clone https://github.com/juanchurtado1991/ghost-serializer.git
cd ghost-serializer
./gradlew ciTestJvmParse and hydrate Kotlin models at up to 1.2 GB/s — drop in beside the serializer you already use.
Ghost sits beside kotlinx.serialization, Jackson, Gson, or Moshi. Annotate only the hot DTOs, leave everything else alone, and migrate when you want.
Quick Start · Maven Central · Live Ghost Speedtest · Playground · Benchmarks · Coverage · Roadmap
You already have a JSON stack. Ghost is the optimization layer for the endpoints and models that show up in profiles:
ByteArray and Okio streams without String round-trips@GhostSerialization
data class User(val id: Long, val name: String, val email: String)
val user: User = Ghost.deserialize(responseBytes) // hot path
val json: String = Ghost.encodeToString(user)Your other models keep using KotlinX, Jackson, Gson, or Moshi — unchanged.
Twitter macro fixture (631 KB). Three views of the same decode run — throughput ↑, latency ↓, memory ↓:
| Ghost | KSER | Moshi | Ghost vs slowest | |
|---|---|---|---|---|
| Decode string | 1.2 GB/s · 514 µs · 361 KB | 0.718 GB/s · 879 µs · 1338 KB | 0.374 GB/s · 1688 µs · 1709 KB | ~3.3× faster · 79% less memory |
| Decode bytes | 1.05 GB/s · 600 µs · 621 KB | 0.424 GB/s · 1489 µs · 4297 KB | 0.275 GB/s · 2297 µs · 4668 KB | ~3.8× faster · 87% less memory |
| Decode streaming | 0.53 GB/s · 1194 µs · 1269 KB | 0.193 GB/s · 3270 µs · 1905 KB | 0.426 GB/s · 1482 µs · 1709 KB | ~2.7× faster · 33% less memory |
Full tables + how to run them → Benchmarks · also ktor-ghost on HTTP Arena (+14% vs plain Ktor).
Host:
./gradlew :ghost-benchmark:benchmarkTwitter -PskipTests(full profile, 10 000-iteration warmup) on Ubuntu 24.04 (Linux x86_64) · AMD Ryzen 9 7900X (12 cores / 24 threads, up to ~5.7 GHz boost) · 64 GB RAM · Eclipse Temurin JDK 17 (GradlejvmToolchain(17)) · Kotlin 2.4.0. Absolute GB/s varies by machine; relative Ghost vs KSER/Moshi rankings are what the regression gate tracks.
| Stack | How Ghost fits |
|---|---|
| Ktor |
ghost() beside json() — Ghost DTOs first, KotlinX for the rest |
| Retrofit |
GhostConverterFactory before Gson / Moshi / KotlinX |
| Spring Boot | starter routes @GhostSerialization DTOs; Jackson keeps everything else |
| Direct calls | only the call sites you profile |
Step-by-step → Quick Start
| Targets | |
|---|---|
| Published (Maven Central 1.3.0) | Android · iOS · JVM · Wasm (wasmJs) |
| Toolchain | Kotlin 2.4.0 · KSP 2.3.10 · Ktor 3.5.x |
Also: Retrofit 2.11+, Spring Boot 3.4+ (MVC + WebFlux), YAML (application/yaml), Proto3 JSON mapping.
Details → Modules
| Guide | What you'll find |
|---|---|
| Quick Start | First DTO in minutes |
| Installation | Catalog, KSP, opt-outs |
| Android & Retrofit | Apps, OkHttp, converters |
| KMP & Ktor | Shared module + client/server |
| iOS & Swift | XCFramework bridge |
| Spring Boot | MVC / WebFlux + Jackson |
| YAML |
decodeFromYaml, Ktor/Spring/Retrofit adapters |
| Proto3 JSON | WKTs and mapping rules |
| Advanced Features | Resilience, flatten, RawJson |
| Architecture | Prediction, SWAR, hashed dispatch, pools |
| Roadmap | OpenAPI codegen, tests, badges |
| Contributing | Tests and PR checklist |
git clone https://github.com/juanchurtado1991/ghost-serializer.git
cd ghost-serializer
./gradlew ciTestJvm