change from fastjson to Gson

This commit is contained in:
jiahua.liu 2020-03-29 23:21:35 +08:00
parent 411157bada
commit 4b34eaa5e0
3 changed files with 14 additions and 11 deletions

View File

@ -54,7 +54,9 @@ object WrapperMain {
f.isVisible = true
uiLog("正在进行版本检查\n")
val dic = System.getProperty("user.dir")
uiLog("工作目录: ${dic}\n")
uiLog("若无法启动, 请尝试清除工作目录下/content/文件夹\n")
var uiOpen = true
GlobalScope.launch {
while (isActive && uiOpen) {
@ -73,6 +75,7 @@ object WrapperMain {
}
}
uiLog("版本检查完成, 启动中\n")
runBlocking {
MiraiDownloader.downloadIfNeed(true)
}

View File

@ -26,7 +26,7 @@ dependencies {
compileOnly("net.mamoe:mirai-core-qqandroid-jvm:${Versions.Mirai.core}")
implementation(group = "com.alibaba", name = "fastjson", version = "1.2.62")
implementation("com.google.code.gson:gson:2.8.6")
implementation(group = "org.yaml", name = "snakeyaml", version = "1.25")
implementation(group = "com.moandjiezana.toml", name = "toml4j", version = "0.7.2")
implementation(kotlin("stdlib-jdk8"))

View File

@ -11,15 +11,14 @@
package net.mamoe.mirai.console.plugins
import com.alibaba.fastjson.JSON
import com.alibaba.fastjson.JSONObject
import com.alibaba.fastjson.TypeReference
import com.alibaba.fastjson.parser.Feature
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.moandjiezana.toml.Toml
import com.moandjiezana.toml.TomlWriter
import kotlinx.serialization.Serializable
import kotlinx.serialization.UnstableDefault
import net.mamoe.mirai.utils.MiraiInternalAPI
import net.mamoe.mirai.utils._miraiContentToString
import net.mamoe.mirai.utils.io.encodeToString
import org.yaml.snakeyaml.Yaml
import java.io.File
@ -478,16 +477,17 @@ class JsonConfig internal constructor(
if (content.isEmpty() || content.isBlank() || content == "{}") {
return ConfigSectionImpl()
}
return JSON.parseObject(
content,
object : TypeReference<ConfigSectionImpl>() {},
Feature.OrderedField
val gson = Gson()
val typeRef = object : TypeToken<Map<String, Any>>(){}.type
return ConfigSectionDelegation(
gson.fromJson(content, typeRef)
)
}
@UnstableDefault
override fun serialize(config: ConfigSection): String {
return JSONObject.toJSONString(config)
val gson = Gson()
return gson.toJson(config.toMap())
}
}