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:
Gradle (Groovy)
Gradle (Kotlin)
Maven
implementation "io.ktor:ktor-jackson:$ktor_version"
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.