Skip to content
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

支持使用 json 保存与读取 PluginDataPluginConfig #2498

Merged
merged 2 commits into from
Mar 22, 2023

Conversation

NoMathExpectation
Copy link
Contributor

由于 console 保存 PluginDataPluginConfig 使用的 yamlkt 对于多态的支持不够充足,而 kotlinx.serialization 提供的 json 序列化相比更稳定且支持更多功能,所以在此添加对 json 格式储存数据的支持,以更加方便稳定地储存多态类数据。

@Him188 Him188 self-requested a review February 13, 2023 00:59
@Him188 Him188 added t:feature 类型: 新特性 s:console 子系统: mirai-console labels Feb 13, 2023
@Him188 Him188 added this to the 2.15.0-RC milestone Feb 13, 2023
@Him188
Copy link
Member

Him188 commented Feb 19, 2023

不错的想法

但是有没有试过在 map 里用 Any? YAML 用的是 net.mamoe.yamlkt.YamlDynamicSerializer, 我记得 JSON 不支持. JSON 的话估计可以用 @Contextual 实现

@NoMathExpectation
Copy link
Contributor Author

确实, json 不支持在 Map 中使用 Any,我尝试改写测试样例,会得到 Serializer for (类型) cannot be serialized polymorphically with class discriminator. 的提示。所以会有什么影响吗?

@Him188
Copy link
Member

Him188 commented Feb 19, 2023

不会有什么影响, 就是需要在文档说明, 试试 @Contextual 或提供 serializersModule 能不能解决?

@NoMathExpectation
Copy link
Contributor Author

NoMathExpectation commented Feb 19, 2023

不会有什么影响, 就是需要在文档说明, 试试 @Contextual 或提供 serializersModule 能不能解决?

用 serializersModule 注册多态会报错 Serializer for (类型) cannot be serialized polymorphically with class discriminator.
@Contextual 需要自己手写一个 KSerializer<Any> 再注册到 serializersModule 里。
Int 为例:
image
image

Copy link
Member

@Him188 Him188 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

实现其实不太可扩展, 但感觉 PluginData 整个设计就很烂, 也不太好改...

@Him188 Him188 requested a review from Karlatemp March 20, 2023 15:46
@Him188 Him188 added z:ready-to-merge 状态: PR 已经可以合并, 正在等待一些安排 and removed z:ready-to-merge 状态: PR 已经可以合并, 正在等待一些安排 labels Mar 20, 2023
@Him188 Him188 merged commit cb603ad into mamoe:dev Mar 22, 2023
StageGuard pushed a commit to StageGuard/mirai that referenced this pull request Apr 14, 2023
* Supports PluginData store with json format.

* Reformat code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
s:console 子系统: mirai-console t:feature 类型: 新特性
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants