I used kotlin lazy property in serializeable class...
# android
s
I used kotlin lazy property in serializeable class. It works well in debug mode build, but crashed in release build (with proguard). I've solve this issue by adding below rule to proguard settings.
Copy code
-keepclassmembers class * {
 *** writeReplace();
}
androdi application code: https://gist.github.com/kingori/518e8afcb6fb4d90b81eb8348395f39e post on this issue( in Korean) : https://steemit.com/kotlin/@kingori2/kotlin-lazy-field-serialize-proguard
g
Maybe better exclude lazy property from serilization (add
@Transient
annotation)
s
@gildor Yes, I agree. It can help avoid that problem. But every developers should keep that in mind, so that problem could be potential source of error.
g
Yes, and the main source of those problems is
java.io.Serializable
which should be used really carefully
đź‘Ť 1
kotlin delegate is not something unique, you have all those problems in many other cases if you just add Serializable to class
s
Yes.
Parcelable
could be another good solution. I think it does not have all these kind of problems.
g
At least Parcelable is very explicit about implementation, doesn’t work with Serializable magic
also should be faster