0Pricing
Kotlin Academy · Lesson

Content Negotiation and kotlinx.serialization

Configure JSON serialization and deserialize request bodies automatically.

What Is Content Negotiation?

Content negotiation is the HTTP mechanism by which a client and server agree on the format of the response body. The client sends an Accept header; the server picks the best matching format. Ktor's ContentNegotiation plugin automates this.

Adding Dependencies

Add the ContentNegotiation plugin and the kotlinx.serialization JSON converter:

dependencies {
    implementation("io.ktor:ktor-server-content-negotiation:2.3.12")
    implementation("io.ktor:ktor-serialization-kotlinx-json:2.3.12")
    implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.1")
}

All lessons in this course

  1. Ktor Project Setup: embeddedServer and Application Modules
  2. Routing and Typed Parameters
  3. Content Negotiation and kotlinx.serialization
  4. Authentication Plugins: JWT and Session
← Back to Kotlin Academy