



To serialize the data class Person into JSON, we need to include the Serializable annotation in the class: import Serializable data class Person ( val gender. And here comes Kotlin with its magical annotations. Firstly, let’s discuss briefly how we can serialize and deserialize objects in Kotlin using Kotlin’s out-of-the-box kotlinx-serialization library. But implementing Parcelable always seemed like a lot of additional work. Provides JSON, Protobuf, CBOR, Hocon and Properties formats. Supports Kotlin classes marked as Serializable and standard collections. In almost every single one of them we can clearly see that Parcelable crushes Serializable in terms of speed. Kotlin serialization consists of a compiler plugin, that generates visitor code for serializable classes, runtime library with core serialization API and support libraries with various serialization formats. Applying Serializable to the Kotlin class instructs the serialization plugin to automatically generate implementation of KSerializer for the current class, that can be used to serialize and deserialize the class. We all have heard about the Parcelable vs Serializable wars, but since the annotation is going to lose its experimental status any day now, I decided to revisit articles that compare the speed of both these implementations. This chapter shows the basic use of Kotlin Serialization and explains its core concepts. The main entry point to the serialization process.
