Hello. Does kotlinx.serialization support Java's EnumSet or do I need to create custom serializer for them?
j
jw
03/29/2023, 12:03 PM
If your property type is EnumSet then yes. Otherwise if you're using an EnumSet and assigning to a Set property it will work just fine.
d
Daniel
03/29/2023, 12:06 PM
What format will be used for Set type?
j
jw
03/29/2023, 12:08 PM
It will be serialized as a collection in whatever format you're using
d
Daniel
03/29/2023, 2:27 PM
If I were to implement KSerializer for EnumSet, can I write it as generic? I guess not since I wont know max size of ordinal in the Enum inside EnumSet, right?
j
jw
03/29/2023, 2:47 PM
It should be possible to do it generically for any enum
d
Daniel
03/30/2023, 7:25 AM
I am trying to write such KSerializer in a generic way, but I am having trouble creating EnumSet instances in deserialize() when the type of the enum inside of it is erased (ie. when using EnumSet<*> or <T: Enum<T>> with <EnumSet<T>>). Could you please point me into the right direction / suggest an approach?