alakazam.kotlin.serialization.SimpleSerializer.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlin-serialization Show documentation
Show all versions of kotlin-serialization Show documentation
A set of useful functions and extensions for working with Kotlin Serialization.
The newest version!
package alakazam.kotlin.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
@Suppress("UnnecessaryAbstractClass")
public abstract class SimpleSerializer(
serialName: String,
private val constructor: (String) -> T,
) : KSerializer {
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor(serialName, PrimitiveKind.STRING)
override fun serialize(encoder: Encoder, value: T) {
encoder.encodeString(value.toString())
}
override fun deserialize(decoder: Decoder): T = constructor(decoder.decodeString())
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy