commonMain.io.github.kevincianfarini.monarch.mixins.JsonFeatureFlag.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlinx-serialization-mixin-jvm Show documentation
Show all versions of kotlinx-serialization-mixin-jvm Show documentation
Multiplatform mixin that decode JSON feature flags
The newest version!
package io.github.kevincianfarini.monarch.mixins
import io.github.kevincianfarini.monarch.FeatureFlag
import kotlinx.serialization.KSerializer
import kotlinx.serialization.json.Json
/**
* An implementation of [FeatureFlag] that supports deserializing JSON strings to [OptionType].
*/
public abstract class JsonFeatureFlag(
public override val key: String,
public override val default: OptionType,
/**
* The [KSerializer] used to marshall objects between their JSON string representation and their object
* representation.
*/
private val serializer: KSerializer,
) : FeatureFlag {
internal fun deserialize(raw: String, json: Json): OptionType {
return json.decodeFromString(serializer, raw)
}
internal fun serializedDefault(json: Json): String {
return json.encodeToString(serializer, default)
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy