baasbox / Android-SDK

BaasBox Android SDK
Apache License 2.0
27 stars 26 forks source link

Exception while read the JsonObject in Android Bundle #15

Closed andresmafra closed 10 years ago

andresmafra commented 10 years ago

Im getting the following exception while reading the JsonObject after I insert it on new Activity Bundle:

android.os.BadParcelableException: ClassNotFoundException when unmarshalling: com.baasbox.android.json.JsonArray

The code for put the bundle:

Intent locationDetailsActivity = new Intent(getActivity().getApplicationContext(),LocationDetailsActivity.class);

Bundle bundle = new Bundle();
bundle.putParcelable(SELECTED_LOCATION, locationObject);

locationDetailsActivity.putExtras(bundle);

The code for retrieve the values:

JsonObject location = getIntent().getExtras().getParcelable(Constants.SELECTED_LOCATION);

if (location != null) {
    getActionBar().setTitle(location.getString(BaasBoxConstants.LOCATION_NAME_FIELD));
}
eliantor commented 10 years ago

It seems to be a known issue with custom parcelable used in intents.

http://stackoverflow.com/questions/2307476/classnotfoundexception-when-using-custom-parcelable https://code.google.com/p/android/issues/detail?id=6822

We will investigate a workaround for this.

andresmafra commented 10 years ago

I´ve tried the comment on https://code.google.com/p/android/issues/detail?id=6822 but it doesnt worked. Have you another WA? Thanks!

UPDATE:

I think this explanation is more appropriate for the error on SDK:

http://stackoverflow.com/a/18126250/1442795

Maybe we need to implement this on the following code (java com.baasbox.android.json.JsonArray)?

//OLD
    JsonArray(Parcel source) {
        this();
        source.readList(list, null);
    }

//FIX

    JsonArray(Parcel source) {
        this();
        source.readList(list, getClass().getClassLoader());
    }

What do you think about?

andresmafra commented 10 years ago

As a workaround Im using the utility methods on the SDK:

encode()
decode()

This format the return of JsonObject in a String and so i can pass it to the activity(using the serializable behavior). Of course serializable has a loss of performance, but for a WA is acceptable.

eliantor commented 10 years ago

Thanks for the suggestion, we'll try and test if the fix works. If so it would surely be in the next release.