Ktor 1.4.0 Help

kotlinx.serialization

The SerializationConverter feature allows you to handle JSON content in your application easily using kotlinx.serialization library.

This feature is a ContentNegotiation converter.

Basic usage

To install the feature by registering a JSON content convertor using kotlinx.serialization:

install(ContentNegotiation) { serialization() }

Configuration

The serialization() function has two optional parameters with default arguments:

  • contentType provides a way to specify which content types it should handle, ContentType.Application.Json by default.

  • json provides ability to configure JSON formatter, Json(DefaultJsonConfiguration) by default.

Advanced example:

install(ContentNegotiation) { serialization( contentType = ContentType.Application.Json, json = Json( DefaultJsonConfiguration.copy( prettyPrint = true ) ) ) }
Last modified: 03 September 2020