在Kotlin中枚举注释 [英] Enum annotations in Kotlin
本文介绍了在Kotlin中枚举注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个由Gson序列化/反序列化的枚举:
I have an enumeration that is serialized/deserialized by Gson:
enum class PacketType {
NONE;
[SerializedName("request")]
REQUEST;
[SerializedName("response")]
RESPONSE;
[SerializedName("event")]
EVENT;
}
不幸的是,我注意到Gson忽略 SerializedName
注释并使用枚举值的大写名称。我决定找出为什么序列化不能按预期工作,并发现Kotlin放弃枚举值的所有注释。我怎样才能使这些注释出现在生成的字节码?
Unfortunately, I noticed that Gson ignores SerializedName
annotations and uses upper case names for enum values. I decided to find out why serialization doesn't work as intended and found out that Kotlin drops all annotations for enum values. How can I make these annotations appear in generated bytecode?
推荐答案
看起来像一个bug。请向问题跟踪器报告。
Looks like a bug to me. Please report to the issue tracker.
作为临时解决方法,您可以使用Java编写此类
As a temporary workaround, you can write this class in Java
这篇关于在Kotlin中枚举注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文