Skip to content

Commit

Permalink
Merge pull request #356 from simpleton/bug/array_in_parcelable
Browse files Browse the repository at this point in the history
FIX #354  `android.os.BadParcelableException: ClassNotFoundException …
  • Loading branch information
joelittlejohn committed May 15, 2015
2 parents c048810 + a9846c4 commit f062aef
Showing 1 changed file with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ public void addWriteToParcel(JDefinedClass jclass) {
method.param(int.class, "flags");

for (JFieldVar f : jclass.fields().values()) {
method.body().invoke(dest, "writeValue").arg(f);
if (f.type().isArray()) {
method.body().invoke(dest, "writeList").arg(f);
} else {
method.body().invoke(dest, "writeValue").arg(f);
}
}
}

Expand Down Expand Up @@ -66,7 +70,21 @@ private void addCreateFromParcel(JDefinedClass jclass, JDefinedClass creatorClas
JVar in = createFromParcel.param(Parcel.class, "in");
JVar instance = createFromParcel.body().decl(jclass, "instance", JExpr._new(jclass));
for (JFieldVar f : jclass.fields().values()) {
createFromParcel.body().assign(instance.ref(f), JExpr.cast(f.type(), in.invoke("readValue").arg(JExpr.direct(f.type().erasure().name() + ".class.getClassLoader()"))));
if (f.type().isArray()) {
createFromParcel.body()
.invoke(in, "readList")
.arg(instance.ref(f))
.arg(JExpr.direct(f.type().erasure().name() + ".class.getClassLoader()"));
} else {
createFromParcel.body().assign(
instance.ref(f),
JExpr.cast(
f.type(),
in.invoke("readValue").arg(JExpr.direct(f.type().erasure().name() + ".class.getClassLoader()"))
)
);
}

}
createFromParcel.body()._return(instance);
}
Expand Down

0 comments on commit f062aef

Please sign in to comment.