Ktor Server ↔ Ktor Client: Content Negotiation Interoperability
0 reputation · 19 Aug 2020, 23:09 UTC
Ktor Server ↔ Ktor Client: Content Negotiation Interoperability
When a Ktor Server and a Ktor Client are deployed together, both sides must agree on how JSON payloads are serialized. The current ContentNegotiation plug‑in allows separate registration of kotlinx.serialization or gson, but the API does not provide a single, unified configuration path. This fragmentation creates uncertainty for libraries that need a stable contract for JSON handling, especially when the server uses kotlinx.serialization while the client relies on gson.
Given that the Ktor community has not yet decided whether to merge these plug‑ins into a single json(...) call that accepts a serializer strategy, developers face a design dilemma: choose a specific serializer per component or risk runtime incompatibilities.
What are the trade‑offs of introducing a unified JSON serializer API? How will backward compatibility be maintained for existing projects that register separate plug‑ins? Will the new API enforce identical serializer configurations across server and client to guarantee round‑trip correctness?