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

commonMain.com.bselzer.ktx.serialization.context.YamlContext.kt Maven / Gradle / Ivy

The newest version!
package com.bselzer.ktx.serialization.context

import com.bselzer.ktx.serialization.merge.YamlMergeOptions
import com.bselzer.ktx.serialization.merge.YamlMerger
import kotlinx.serialization.DeserializationStrategy
import net.mamoe.yamlkt.Yaml
import net.mamoe.yamlkt.YamlElement
import net.mamoe.yamlkt.YamlList
import net.mamoe.yamlkt.YamlMap

open class YamlContext(
    override val instance: Yaml
) : StringFormatContext(instance) {
    companion object Default : YamlContext(Yaml)

    override fun  String.decode(deserializer: DeserializationStrategy): T = instance.decodeFromString(deserializer, this)

    fun YamlElement.merge(
        other: YamlElement?,
        options: YamlMergeOptions = YamlMergeOptions.Default
    ): YamlElement = YamlMerger(options).run { merge(other) }

    fun YamlMap.merge(
        other: YamlMap,
        options: YamlMergeOptions = YamlMergeOptions.Default
    ): YamlMap = YamlMerger(options).run { merge(other) }

    fun YamlList.merge(
        other: YamlList,
        options: YamlMergeOptions = YamlMergeOptions.Default
    ): YamlList = YamlMerger(options).run { merge(other) }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy