The previous heading shows how to store data as a JSON document. But how does it work? Compiling the Student class code seen earlier yields a jar containing these classes:
Student.class, Student$Companion.class, and Student$$serializer.class.
If you were to look at the Student class companion object, you would see the following:
public object `$serializer` : kotlinx.serialization.internal.GeneratedSerializer<io.stepi.Student>
When you call Student.serializer(), you will get an instance of the generated serializer. Using javap you can get the raw bytecode to see what the compiler has actually generated—this is for those with an elevated curiosity and at least basic Java bytecode knowledge.
As seen in the preceding code snippet, GeneratedSerializer is an interface defined by thekotlinx.serialization framework. Its definition is the following:
interface...