kind
The kind of the serialized form that determines the shape of the serialized data. Formats use serial kind to add and parse serializer-agnostic metadata to the result.
For example, JSON format wraps classes and StructureKind.MAP into brackets, while ProtoBuf just serialize these types in separate ways.
Kind should be consistent with the implementation, for example, if it is a primitive, then its element count should be zero and vice versa.
Example of introspecting kinds:
@Serializable
class User(val name: String)
val userDescriptor = User.serializer().descriptor
userDescriptor.kind // Returns StructureKind.CLASS
userDescriptor.getElementDescriptor(0).kind // Returns PrimitiveKind.STRING
Content copied to clipboard