Add serializersModule

This commit is contained in:
Him188 2020-09-18 23:30:40 +08:00
parent f40dd189f2
commit ca40a292cf
2 changed files with 17 additions and 1 deletions

View File

@ -7,11 +7,13 @@
* https://github.com/mamoe/mirai/blob/master/LICENSE * https://github.com/mamoe/mirai/blob/master/LICENSE
*/ */
@file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER", "EXPOSED_SUPER_CLASS", "NOTHING_TO_INLINE") @file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER", "EXPOSED_SUPER_CLASS", "NOTHING_TO_INLINE", "unused")
package net.mamoe.mirai.console.data package net.mamoe.mirai.console.data
import kotlinx.serialization.KSerializer import kotlinx.serialization.KSerializer
import kotlinx.serialization.modules.EmptySerializersModule
import kotlinx.serialization.modules.SerializersModule
import net.mamoe.mirai.console.internal.data.PluginDataImpl import net.mamoe.mirai.console.internal.data.PluginDataImpl
import net.mamoe.mirai.console.internal.data.getAnnotationListForValueSerialization import net.mamoe.mirai.console.internal.data.getAnnotationListForValueSerialization
import net.mamoe.mirai.console.internal.data.valueName import net.mamoe.mirai.console.internal.data.valueName
@ -72,6 +74,9 @@ public abstract class AbstractPluginData : PluginData, PluginDataImpl() {
public final override val updaterSerializer: KSerializer<Unit> public final override val updaterSerializer: KSerializer<Unit>
get() = super.updaterSerializer get() = super.updaterSerializer
@ConsoleExperimentalApi
public override val serializersModule: SerializersModule = EmptySerializersModule
/** /**
* 当所属于这个 [PluginData] [Value] [][Value.value] 被修改时被调用. * 当所属于这个 [PluginData] [Value] [][Value.value] 被修改时被调用.
*/ */

View File

@ -18,6 +18,8 @@
package net.mamoe.mirai.console.data package net.mamoe.mirai.console.data
import kotlinx.serialization.KSerializer import kotlinx.serialization.KSerializer
import kotlinx.serialization.modules.SerializersModule
import kotlinx.serialization.modules.serializersModuleOf
import net.mamoe.mirai.console.compiler.common.ResolveContext import net.mamoe.mirai.console.compiler.common.ResolveContext
import net.mamoe.mirai.console.compiler.common.ResolveContext.Kind.RESTRICTED_NO_ARG_CONSTRUCTOR import net.mamoe.mirai.console.compiler.common.ResolveContext.Kind.RESTRICTED_NO_ARG_CONSTRUCTOR
import net.mamoe.mirai.console.data.java.JAutoSavePluginData import net.mamoe.mirai.console.data.java.JAutoSavePluginData
@ -124,6 +126,15 @@ public interface PluginData {
@ConsoleExperimentalApi @ConsoleExperimentalApi
public fun onValueChanged(value: Value<*>) public fun onValueChanged(value: Value<*>)
/**
* 用于支持多态序列化.
*
* @see SerializersModule
* @see serializersModuleOf
*/
@ConsoleExperimentalApi
public val serializersModule: SerializersModule
/** /**
* 当这个 [PluginData] 被放入一个 [PluginDataStorage] 时调用 * 当这个 [PluginData] 被放入一个 [PluginDataStorage] 时调用
*/ */