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

commonMain.com.bselzer.ktx.value.enumeration.StringEnum.kt Maven / Gradle / Ivy

The newest version!
package com.bselzer.ktx.value.enumeration

import com.bselzer.ktx.serialization.context.JsonContext.Default.decode
import com.bselzer.ktx.serialization.context.JsonContext.Default.decodeOrNull
import com.bselzer.ktx.serialization.serializer.StringEnumSerializer
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable

@Serializable(with = StringEnumSerializer::class)
class StringEnum @PublishedApi internal constructor(
    private val value: String,
    private val serializer: KSerializer
) : BindableEnum where T : Enum {
    override fun toEnum(): T = value.decode(serializer)
    override fun toEnumOrNull(): T? = value.decodeOrNull(serializer)
    override fun toString(): String = value
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy