-
Notifications
You must be signed in to change notification settings - Fork 665
Closed as not planned
Description
Containing app will crash with VerifyError when attempting to serialize a sealed class field using a custom serializer annotated with @Serializer.
I have implemented a workaround based on this almost identical stackoverflow post:
https://stackoverflow.com/questions/50151499/verifyerror-rejecting-class-serializer
This only happens on Android 6.
To Reproduce
@Serializable
sealed class DeviceType(open val name: String) {
object SetTopBox : DeviceType("settop")
object Mobile : DeviceType("mobile")
object Tablet : DeviceType("tablet")
@Serializer(forClass = DeviceType::class)
companion object : KSerializer<DeviceType> {
override fun serialize(encoder: Encoder, obj: DeviceType) {
encoder.encodeString(obj.name)
}
}
}
Resulting crash is:
java.lang.VerifyError: Rejecting class com.producer.data.model.DeviceType$Companion because it failed compile-time verification (declaration of 'com.producer.data.model.DeviceType$Companion' appears in /data/app/com.producer-1/base.apk:classes7.dex)
Expected behavior
Serialization successful - no crash.
Environment
- Kotlin version: 1.3.72
- Library version: 0.20.0
- Kotlin platforms: JVM
- Gradle version: 4.0.1
- IDE version: n/a
- Other relevant context: Android 6.0.1
AleksandrKrasnoperov, kuFEAR and tujhex