-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2.13.0-M1 版本,需要序列化的类中带有 MessageSourceKind 时,编译报错, SERIALIZER_NOT_FOUND #2230
Comments
看起来是 serialization 的编译器插件问题 (即 Kotlin 问题) |
试了一下按上面的代码可以复现. @Serializable
enum class MyEnum {
VALUE1
}
fun main() {
val serializer = MessageSourceKind.Companion.serializer()
println(serializer)
println(MyEnum.serializer())
} 运行结果: net.mamoe.mirai.message.data.MessageSourceKind$$serializer@66d2e7d9
com.example.MyEnum$$serializer@7c0e2abd 可能 kotlinx-serialization 在序列化或反序列化 KotlinMetadata 时出了什么问题 |
测试: |
测试:
fun main() {
println(MessageOriginKind.serializer()) // net.mamoe.mirai.message.data.MessageOriginKind$$serializer@39c0f4a
println(Json.encodeToString(MessageOriginKind.serializer(), MessageOriginKind.MUSIC_SHARE)) // "MUSIC_SHARE"
} 编译正常, 运行正常
@Serializable
data class TestData(
val kind: MessageSourceKind
// ^^^^^^^^^^^^^^^^^ [SERIALIZER_NOT_FOUND] Serializer has not been found for type 'MessageSourceKind'. To use context serializer as fallback, explicitly annotate type or property with @Contextual
) 编译失败:
编译运行成功, 输出正常 @Serializable
enum class MyEnum {
VALUE1
}
fun main() {
val serializer = MessageSourceKind.Companion.serializer()
println(serializer) // net.mamoe.mirai.message.data.MessageSourceKind$$serializer@66d2e7d9
println(MyEnum.serializer()) // com.example.MyEnum$$serializer@7c0e2abd
} |
是 relocate 导致的 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
问题描述
MessageSourceKind
无法直接在kotlinx.serialization
下使用,会报警告 [SERIALIZER_NOT_FOUND]复现
mirai-core 版本
2.13.0-M1
bot-protocol
ANDROID_PHONE
其他组件版本
No response
系统日志
网络日志
No response
补充信息
No response
The text was updated successfully, but these errors were encountered: