diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/Setting.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/Setting.kt index 5aeb0f2e3..87c75855e 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/Setting.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/Setting.kt @@ -56,7 +56,7 @@ abstract class Setting : SettingImpl() { return this } - override fun toString(): String = yaml.stringify(this.serializer, this) + override fun toString(): String = yamlForToString.stringify(this.serializer, this) } @Suppress("UNCHECKED_CAST") diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/internal/internal.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/internal/internal.kt index 84a9c1b72..92d22dd46 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/internal/internal.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/internal/internal.kt @@ -15,6 +15,7 @@ import kotlinx.serialization.builtins.serializer import net.mamoe.mirai.console.setting.SerialName import net.mamoe.mirai.console.setting.Setting import net.mamoe.mirai.console.setting.Value +import net.mamoe.mirai.utils.MiraiExperimentalAPI import net.mamoe.yamlkt.Yaml import net.mamoe.yamlkt.YamlConfiguration import kotlin.reflect.KProperty @@ -58,7 +59,7 @@ internal abstract class SettingImpl { companion object { @JvmStatic - internal val yaml = + internal val yamlForToString = Yaml( configuration = YamlConfiguration( nonStrictNullability = true, @@ -75,6 +76,7 @@ internal class SettingUpdaterSerializer( private val instance: Setting ) : KSerializer { override val descriptor: SerialDescriptor by lazy { + @OptIn(MiraiExperimentalAPI::class) SerialDescriptor(instance.serialName) { for ((value, property) in instance.valueList) { element(property.serialNameOrPropertyName, value.serializer.descriptor, annotations, true) @@ -97,9 +99,8 @@ internal class SettingUpdaterSerializer( while (true) { val index = this.decodeElementIndex(descriptor) if (index == CompositeDecoder.READ_DONE) return@decodeStructure SettingSerializerMark - val value = instance.valueList[index].first - - this.decodeSerializableElement( + val value = instance.valueList[index].first as Value + value.value = this.decodeSerializableElement( descriptor, index, value.serializer @@ -125,6 +126,7 @@ internal class SettingUpdaterSerializer( } +// until https://github.com/Him188/yamlkt/issues/2 fixed internal fun CompositeEncoder.encodeElementSmart( descriptor: SerialDescriptor, index: Int,