Easy class serialization on Android using the @Parcelize annotation
In this recipe, we are going to make use of the @Parcelize annotation to simplify the implementation of the Android Parcelable interface, allowing us to serialize objects efficiently. @Parcelize is available in the Kotlin Android Extensions plugin and provides automatic code-generation for Kotlin classes that implement the Parcelable interface.
Getting ready
We are going to implement the Android instrumented test case in order to verify the effect of a class serialization and deserialization in action. To make use of the Android KTX library, we need to add it to the project dependencies. In our case, we will need it in the android-test module. We can add it with the following declaration:
androidTestImplementation 'androidx.core:core-ktx:1.0.+'
In order to make use of the Kotlin Android Extensions plugin, we need to enable it in the Android project module-level build.gradle script by adding the following declaration:
apply plugin...