All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.serialization.NewLineListSerializer.kt Maven / Gradle / Ivy

package qbittorrent.models.serialization

import kotlinx.serialization.KSerializer
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder

internal object NewLineListSerializer : KSerializer> {

    override val descriptor: SerialDescriptor =
        PrimitiveSerialDescriptor("NewlineList", PrimitiveKind.STRING)

    override fun deserialize(decoder: Decoder): List {
        return decoder.decodeString().lines().filter { it.isNotEmpty() }
    }

    override fun serialize(encoder: Encoder, value: List) {
        encoder.encodeString(value.joinToString("\n"))
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy