From b3b34c19d1e7f977a84f48201629b7f6c1058cf8 Mon Sep 17 00:00:00 2001 From: Him188 Date: Fri, 18 Dec 2020 16:52:39 +0800 Subject: [PATCH] JSON encode defaults --- backend/mirai-console/src/data/AutoSavePluginData.kt | 7 +++++-- .../src/internal/data/MultiFilePluginDataStorageImpl.kt | 1 + backend/mirai-console/test/data/SettingTest.kt | 7 +++++-- tools/gradle-plugin/src/VersionConstants.kt | 2 +- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/backend/mirai-console/src/data/AutoSavePluginData.kt b/backend/mirai-console/src/data/AutoSavePluginData.kt index 93b334337..5ec51bb68 100644 --- a/backend/mirai-console/src/data/AutoSavePluginData.kt +++ b/backend/mirai-console/src/data/AutoSavePluginData.kt @@ -39,9 +39,12 @@ public open class AutoSavePluginData private constructor( public final override val saveName: String get() = _saveName - private var _saveName: String = saveName + @Suppress("JoinDeclarationAndAssignment") // bug + private lateinit var _saveName: String - public constructor(saveName: String) : this(null) + public constructor(saveName: String) : this(null) { + _saveName = saveName + } @ConsoleExperimentalApi override fun onInit(owner: PluginDataHolder, storage: PluginDataStorage) { diff --git a/backend/mirai-console/src/internal/data/MultiFilePluginDataStorageImpl.kt b/backend/mirai-console/src/internal/data/MultiFilePluginDataStorageImpl.kt index a9e9a1f2c..0144c256e 100644 --- a/backend/mirai-console/src/internal/data/MultiFilePluginDataStorageImpl.kt +++ b/backend/mirai-console/src/internal/data/MultiFilePluginDataStorageImpl.kt @@ -65,6 +65,7 @@ internal open class MultiFilePluginDataStorageImpl( ignoreUnknownKeys = true isLenient = true allowStructuredMapKeys = true + encodeDefaults = true } private val yaml = Yaml.default diff --git a/backend/mirai-console/test/data/SettingTest.kt b/backend/mirai-console/test/data/SettingTest.kt index 3b1fe1f92..1bfa244c4 100644 --- a/backend/mirai-console/test/data/SettingTest.kt +++ b/backend/mirai-console/test/data/SettingTest.kt @@ -24,8 +24,11 @@ internal class PluginDataTest { } @Suppress("unused") - private val jsonPrettyPrint = Json { prettyPrint = true } - private val json = Json {} + private val jsonPrettyPrint = Json { + prettyPrint = true + encodeDefaults = true + } + private val json = Json { encodeDefaults = true } @Test fun testStringify() { diff --git a/tools/gradle-plugin/src/VersionConstants.kt b/tools/gradle-plugin/src/VersionConstants.kt index 736796deb..1d335bff6 100644 --- a/tools/gradle-plugin/src/VersionConstants.kt +++ b/tools/gradle-plugin/src/VersionConstants.kt @@ -10,6 +10,6 @@ package net.mamoe.mirai.console.gradle internal object VersionConstants { - const val CONSOLE_VERSION = "2.0-M1" // value is written here automatically during build + const val CONSOLE_VERSION = "2.0-M1-dev-1" // value is written here automatically during build const val CORE_VERSION = "2.0-M1-dev-3" // value is written here automatically during build } \ No newline at end of file