Veer3383 Veer3383 - 3 months ago 105
Android Question

Parcelable encountered IOException writing serializable object [QUICKBLOX DIALOG]

I am facing an issue in quickblox since 15th April, when Quickblox updated SDK for android to 2.5.2.
The problem that i noticed is like, if i have customData parameter filled for a dialog, then it throws the IOExeption mentioned below. else no issues.

Dialog that casues no issues.


QBDialog{id=xxxx, created_at=2016-19-04 11:36:54,
last_msg_user_id=xxxx, occupants_ids=[xxxx, xxxx, last_message=hey,
last_message_date_sent=1461046124, type=PRIVATE, name=xxxx,
room_jid=null, user_id=xxxx, photo=null, unread_message_count=0,
customData=null}


Dialog that causes Crash.


QBDialog{id=xxxx, created_at=2016-19-04 12:01:00,
last_msg_user_id=xxxx, occupants_ids=[xxxx, xxxx], last_message=hello,
last_message_date_sent=1461047494, type=PRIVATE, name=xxxx,
room_jid=null, user_id=xxxx, photo=null, unread_message_count=1,
customData=QBBaseCustomObject{className='DialogueRelationState',
fields={isFriends=true, location_field=null}}}


Code segment that passes dialogs like above to Activity_chat class

Bundle bundle = new Bundle();
bundle.getString(selectedDialog.toString());
bundle.putSerializable(Activity_Chat.EXTRA_DIALOG, selectedDialog);
Activity_Chat.start(DrawActivity_Chatlist.this, bundle);// error points here


start method of the receiving Activity

public static void start(Context context, Bundle bundle) {

Intent intent = new Intent(context, Activity_Chat.class);
intent.putExtras(bundle);
context.startActivity(intent); //error points here
}


Error Log:

Fatal Exception: java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.quickblox.chat.model.QBDialog)
at android.os.Parcel.writeSerializable(Parcel.java:1323)
at android.os.Parcel.writeValue(Parcel.java:1271)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:618)
at android.os.Bundle.writeToParcel(Bundle.java:1692)
at android.os.Parcel.writeBundle(Parcel.java:643)
at android.content.Intent.writeToParcel(Intent.java:7152)
at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:2663)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1419)
at android.app.Activity.startActivityForResult(Activity.java:3532)
at android.app.Activity.startActivityForResult(Activity.java:3458)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:784)
at android.app.Activity.startActivity(Activity.java:3780)
at android.app.Activity.startActivity(Activity.java:3748)
at com.social.fitspur.activities.Activity_Chat.start(Activity_Chat.java:100)
at com.social.fitspur.activities.DrawActivity_Chatlist$3.onItemClick(DrawActivity_Chatlist.java:198)
at android.widget.AdapterView.performItemClick(AdapterView.java:299)
at android.widget.AbsListView.performItemClick(AbsListView.java:1162)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:2953)
at android.widget.AbsListView$3.run(AbsListView.java:3708)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:149)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
at dalvik.system.NativeStart.main(NativeStart.java)
Caused by java.io.NotSerializableException: org.json.JSONObject$1
at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1366)
at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1673)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1519)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1483)
at java.util.HashMap.writeObject(HashMap.java:995)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1055)
at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1406)
at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1673)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1519)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1483)
at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:981)
at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:368)
at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1076)
at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1406)
at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1673)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1519)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1483)
at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:981)
at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:368)
at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1076)
at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1406)
at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1673)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1519)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1483)
at android.os.Parcel.writeSerializable(Parcel.java:1318)
at android.os.Parcel.writeValue(Parcel.java:1271)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:618)
at android.os.Bundle.writeToParcel(Bundle.java:1692)
at android.os.Parcel.writeBundle(Parcel.java:643)
at android.content.Intent.writeToParcel(Intent.java:7152)
at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:2663)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1419)
at android.app.Activity.startActivityForResult(Activity.java:3532)
at android.app.Activity.startActivityForResult(Activity.java:3458)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:784)
at android.app.Activity.startActivity(Activity.java:3780)
at android.app.Activity.startActivity(Activity.java:3748)
at com.social.fitspur.activities.Activity_Chat.start(Activity_Chat.java:100)
at com.social.fitspur.activities.DrawActivity_Chatlist$3.onItemClick(DrawActivity_Chatlist.java:198)
at android.widget.AdapterView.performItemClick(AdapterView.java:299)
at android.widget.AbsListView.performItemClick(AbsListView.java:1162)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:2953)
at android.widget.AbsListView$3.run(AbsListView.java:3708)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:149)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
at dalvik.system.NativeStart.main(NativeStart.java)


what i understand from this is, it encounters something as JSON in the Dialog which is not serializable and hence the error.

NOTE: This was working fine before April 15th, and i have not made any changes to my custom class too

I have tried upgrading SDK version from v2.5 to v2.5.2, but no use.

Answer

QuickBlox recently added a location_field which was returning a jsonObject but was expecting string. Finally adding this lines while getting dialogs made the trick.

for (QBDialog dialog : dialogs) {
    QBDialogCustomData customData = dialog.getCustomData();
    usersIDs.addAll(dialog.getOccupants());
    if (customData == null) {
        continue;
    }
    HashMap<String, Object> fields = customData.getFields();
    if (!fields.isEmpty()) {
        fields.put("location_field", null);
    }
}
Comments