From 4bb9bc6d9562f1c8ee70e306ee90d487e5d82b20 Mon Sep 17 00:00:00 2001 From: "jiahua.liu" Date: Thu, 13 Feb 2020 17:02:13 +0800 Subject: [PATCH] Super Smart Config --- .../net/mamoe/mirai/plugin/ConfigSection.kt | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/mirai-console/src/main/kotlin/net/mamoe/mirai/plugin/ConfigSection.kt b/mirai-console/src/main/kotlin/net/mamoe/mirai/plugin/ConfigSection.kt index f361d7b67..432f2df1e 100644 --- a/mirai-console/src/main/kotlin/net/mamoe/mirai/plugin/ConfigSection.kt +++ b/mirai-console/src/main/kotlin/net/mamoe/mirai/plugin/ConfigSection.kt @@ -214,9 +214,9 @@ open class ConfigSectionImpl() : ConcurrentHashMap(), ConfigSection interface FileConfig : Config { - fun deserialize(content: String): ConfigSectionImpl + fun deserialize(content: String): ConfigSection - fun serialize(config: ConfigSectionImpl): String + fun serialize(config: ConfigSection): String } @@ -244,31 +244,27 @@ abstract class FileConfigImpl internal constructor( } override fun asMap(): Map { - return content + return content.asMap() } } class JsonConfig internal constructor(file: File) : FileConfigImpl(file) { @UnstableDefault - override fun deserialize(content: String): ConfigSectionImpl { + override fun deserialize(content: String): ConfigSection { if (content.isEmpty() || content.isBlank() || content == "{}") { return ConfigSectionImpl() } - val section = ConfigSectionImpl() - val map: LinkedHashMap = JSON.parseObject( + val section = JSON.parseObject( content, - object : TypeReference>() {}, + object : TypeReference() {}, Feature.OrderedField ) - map.forEach { (t, u) -> - section[t] = u - } return section } @UnstableDefault - override fun serialize(config: ConfigSectionImpl): String { + override fun serialize(config: ConfigSection): String { return JSONObject.toJSONString(config) }