https://kotlinlang.org logo
#serialization
Title
# serialization
e

elizarov

09/28/2017, 7:19 AM
On the other hand, if
MyData
is
@Serializable
, then it opens the road to many formats at once. You can
JSON.stringify(obj)
or you can
ProtoBuf.dump(obj)
and to parcel it you’ll have to have some kind of a helper
Parceller
class and use it like
Parceller.writeTo(parcel, obj)
. You will not be able just to do
parcel.writeValue(obj)
, because a serializable object does not implement
android.os.Parcelable
,
Yes.
k

kingsley

09/28/2017, 4:59 PM
However. Android has some ceremony that comes with it. For example, there has to be a
public static final CREATOR
field. This makes it difficult to simply have a generic solution. How would this be handled?
e

elizarov

09/28/2017, 7:04 PM
This ceremony is only needed for
parcel.readValue()
. You will not be to read it like that with serializable. You'll do
Parceller.read<MyData>(parcel)
6 Views