

But it might not be, if it is some custom implementation of the functional interface () -> Unit, so you should check that and handle the cases when it's not. It will actually be Serializable if it is a function reference (SomeClass::someFunction) or a lambda. In this question: Is there a way to pass a function reference between activities? is following answer: I get following exception: : Parcelable encountered IOException writing serializable object (name = )Īt android.os.Parcel.writeSerializable(Parcel.java:1468)Īt $Companion$SavedState.writeToParcel(CustomView.kt:177)Ĭaused by: java.io.NotSerializableException: When I'm passing this data class to parcelable: parcel.writeSerializable(instance as Serializable) Where this is ViewModel from Android Architecture components 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.

Initialization of class: val instance = Error(throwable,this::loadData) The main entry point to the serialization process. The generated serializer can be accessed with T.serializer () extension function on the class companion, both are generated by the. Kotlin data class: data class Error(val throwable: Throwable, val reloadAction: (() -> Unit)? = null) : Serializable 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.
