KotlinxSerializer

class KotlinxSerializer : JsonSerializer

A JsonSerializer implemented for kotlinx Serializable classes. Since serializers are determined statically, you must set the mapping for each Serializable class to it’s KSerializer manually, using setMapper or register.

KotlinxSerializer().apply {
    register<MySerializable>()
}

Constructors

<init>

KotlinxSerializer(json: Json = Json.plain)

A JsonSerializer implemented for kotlinx Serializable classes. Since serializers are determined statically, you must set the mapping for each Serializable class to it’s KSerializer manually, using setMapper or register.

Functions

read

fun read(type: TypeInfo, body: Input): Any

Read content from response using information specified in type.

register

fun <T : Any> register(mapper: KSerializer<T>): Unit

Set the mapping from T to mapper.

fun <T : Any> register(): Unit

Set the mapping from T to it’s KSerializer. This method only works for non-parameterized types.

registerList

fun <T : Any> registerList(mapper: KSerializer<T>): Unit

Set the mapping from List to mapper.

fun <T : Any> registerList(): Unit

Set the mapping from List to it’s KSerializer. This method only works for non-parameterized types.

setListMapper

fun <T : Any> setListMapper(
    type: KClass<T>,
    serializer: KSerializer<T>
): Unit

Set mapping from type to generated KSerializer.

setMapper

fun <T : Any> setMapper(
    type: KClass<T>,
    serializer: KSerializer<T>
): Unit

Set mapping from type to generated KSerializer.

write

fun write(
    data: Any,
    contentType: ContentType
): OutgoingContent

Convert data object to OutgoingContent.

Inherited Functions

write

open fun write(data: Any): OutgoingContent

Convert data object to OutgoingContent.