KeenenCharles / AndroidUnplash

An unofficial Unsplash API library for Android
MIT License
85 stars 22 forks source link

Unmarshalling exception #17

Closed disparate closed 5 years ago

disparate commented 5 years ago

Hello. I'm getting exception trying to put and get collection as parcelable object. Here's stacktrace

Caused by: java.lang.RuntimeException: Parcel android.os.Parcel@ab4a985: Unmarshalling unknown type code 6488171 at offset 2840 at android.os.Parcel.readValue(Parcel.java:2453) at android.os.Parcel.readListInternal(Parcel.java:2788) at android.os.Parcel.readList(Parcel.java:1845) at com.kc.unsplash.models.CoverPhoto$1.createFromParcel(CoverPhoto.java:60) at com.kc.unsplash.models.CoverPhoto$1.createFromParcel(CoverPhoto.java:44) at android.os.Parcel.readParcelable(Parcel.java:2480) at android.os.Parcel.readValue(Parcel.java:2374) at com.kc.unsplash.models.Collection$1.createFromParcel(Collection.java:66) at com.kc.unsplash.models.Collection$1.createFromParcel(Collection.java:49)

It always happens when read and write to parcel is implemented not correctly (for example wrong types or order).

disparate commented 5 years ago

I checked parcelable implementation for classes from CoverPhoto fields and found only one inconsistency: In the "User" class we have following write method:

public void writeToParcel(Parcel dest, int flags) {
    ...
    dest.writeValue(links);
    dest.writeList(currentUserCollections);
}

And in

protected User(Parcel in) {
    ...
    this.links = ((Links) in.readValue((Links.class.getClassLoader())));
}

So we should either remove currentUserCollections from parceling, or add it to constructor.

KeenenCharles commented 5 years ago

Thanks for letting me know. I just added currentUserCollections to the constructor and released version 1.0.5 with the fix