I'm confused by the way to implement
AbstractEncoder
.
Let's say I want to serialize:
@Serializable
class User(val id: Int)
From what I understand, KotlinX.Serialization will call:
MyEncoder.beginStructure(User.serializer.serialDescriptor).apply {
encodeInt(1234)
endStructure(User.serializer.serialDescriptor)
}
What I don't understand is: when
encodeInt(1234)
is called, how do I know it's the field
id
and not another field that could exist? Am I supposed to store the
serialDescriptor
of the enclosing class, keep track of the index of the last written element, and use that to query the descriptor to know what the field is?
TL;DR: within the implementation of
encodeInt()
I need to find to know the current field's name, but I don't know how to.