Ktor 1.6.7 Help

Jackson

ContentNegotiation provides the built-in Jackson converter for handing JSON data in your application.

Add dependencies

Before registering the Jackson converter, you need to include the following artifacts in the build script:

implementation "io.ktor:ktor-jackson:$ktor_version"
implementation("io.ktor:ktor-jackson:$ktor_version")
<dependency> <groupId>io.ktor</groupId> <artifactId>ktor-jackson</artifactId> <version>${ktor_version}</version> </dependency>

Register the Jackson converter

To register the Jackson converter in your application, call the jackson method:

import io.ktor.jackson.* install(ContentNegotiation) { jackson() }

Inside the jackson block, you can access the ObjectMapper API, for example:

install(ContentNegotiation) { jackson { enable(SerializationFeature.INDENT_OUTPUT) dateFormat = DateFormat.getDateInstance() // ... } }

To learn how to receive and send data, see Receive and send data.

Last modified: 28 May 2021