Closed avidraghavMM closed 1 year ago
Perhaps RawValue
wouldn't help in all cases, because the data
would be written with writeValue. It may crash at runtime if the actual type is not supported by writeValue
.
You can try making T : Parcelable
, if that's possible. However this may also not be working in some cases, e.g. when the actual class is in another ClassLoader
.
A rule of thumb is to avoid generic types. You can make UIState
not Parcelable
, and parcelize it manually in every case where you otherwise specify the actual T
. E.g. you can transform UIState<SomeClass>
to a custom SavedUiStateWithSomeClass : Parcelable
.
If you need this logic in the base code (where UIState
is defined), then you can try supplying additional functions to save and restore UIState<T>
. E.g. this could be:
saveState: (UIState<T>) -> ParcelableContainer
restoreState: (ParcelableContainer) -> UIState<T>
Check out how it is done in Decompose.
Thanks for the quick reply I got it.
Hi, I have a generic parameter in a child class of a Sealed Class in Common Module. Generally if I had to parcelize this parameter in Android Module then I would have the
@RawValue
annotation coming fromkotlinx.parcelize.RawValue
. Is there any annotation provided by this library which can help me do the same?My Sealed Class
Getting this error for the
data
variable ofSuccess
class which is of typeT
:Type is not directly supported by 'Parcelize'. Annotate the parameter type with '@RawValue' if you want it to be serialized using 'writeValue()'