From 1ef3eb471b04360445e31bf8ace125c9252ff71b Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 8 Mar 2020 00:43:52 +0800 Subject: [PATCH] Use custom Json configuration --- .../kotlin/net/mamoe/mirai/utils/SystemDeviceInfo.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/SystemDeviceInfo.kt b/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/SystemDeviceInfo.kt index 3cf5c67b2..efb5cfd47 100644 --- a/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/SystemDeviceInfo.kt +++ b/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/SystemDeviceInfo.kt @@ -14,6 +14,7 @@ import kotlinx.serialization.Serializable import kotlinx.serialization.Transient import kotlinx.serialization.UnstableDefault import kotlinx.serialization.json.Json +import kotlinx.serialization.json.JsonConfiguration import net.mamoe.mirai.utils.io.getRandomByteArray import net.mamoe.mirai.utils.io.getRandomString import java.io.File @@ -25,14 +26,15 @@ import java.io.File fun File.loadAsDeviceInfo(context: Context = ContextImpl()): DeviceInfo { if (!this.exists() || this.length() == 0L) { return SystemDeviceInfo(context).also { - this.writeText(Json.plain.stringify(SystemDeviceInfo.serializer(), it)) + this.writeText(JSON.stringify(SystemDeviceInfo.serializer(), it)) } } - return Json.nonstrict.parse(DeviceInfoData.serializer(), this.readText()).also { + return JSON.parse(DeviceInfoData.serializer(), this.readText()).also { it.context = context } } +private val JSON = Json(JsonConfiguration.Stable) @Serializable @OptIn(ExperimentalUnsignedTypes::class)