Describe the bug
Trying to serialize a object with enums fails with the following error:
SerializationException: Non-serializable class kotlin.Int is not supported by class com.ensarsarajcic.kotlinx.serialization.msgpack.internal.BasicMsgPackEncoder encoder
EnumSerializer from kotlinx-serialization-core-jvm is being used by default. Following it on the debugger, it all goes well until the last line of EnumSerializer.serialize:
override fun serialize(encoder: Encoder, value: T) {
val index = values.indexOf(value)
if (index == -1) {
throw SerializationException(
"$value is not a valid enum ${descriptor.serialName}, " +
"must be one of ${values.contentToString()}"
)
}
encoder.encodeEnum(descriptor, index) //here
}
Where encoder is an instance of BasicMsgPackEncoder. I see that encodeEnum is not implemented in BasicMsgPackEncoder, so that could be part of the issue?
Expected behavior
The enum value should be serialized by its value's name (as the JSON serializer does), e.g. DRUID, KNIGHT, etc.
The same object can be serialized without problems using: Json.encodeToString.
Version
Describe the bug Trying to serialize a object with enums fails with the following error:
This is an example enum:
EnumSerializer
fromkotlinx-serialization-core-jvm
is being used by default. Following it on the debugger, it all goes well until the last line ofEnumSerializer.serialize
:Where
encoder
is an instance ofBasicMsgPackEncoder
. I see thatencodeEnum
is not implemented inBasicMsgPackEncoder
, so that could be part of the issue?Expected behavior The enum value should be serialized by its value's name (as the JSON serializer does), e.g.
DRUID
,KNIGHT
, etc.The same object can be serialized without problems using:
Json.encodeToString
.