I believe that I defined the solution as follows: -
Currently class auto-value-parcel
com.ryanharter.auto.value.parcel.AutoValueParcelExtension
has a method called generateCreator : -
FieldSpec generateCreator(ProcessingEnvironment env, TypeName autoValueType, List<Property> properties, TypeName type, Map<TypeMirror, FieldSpec> typeAdapters) { ClassName creator = ClassName.bestGuess("android.os.Parcelable.Creator"); TypeName creatorOfClass = ParameterizedTypeName.get(creator, type); ... ...
This method generates a Parcelable CREATOR that resembles this
public static final Parcelable.Creator<AutoValue_Amoeba> CREATOR = new Parcelable.Creator<AutoValue_Amoeba>() { @Override public AutoValue_Amoeba createFromParcel(Parcel in) { return new AutoValue_Amoeba( in.readString() ); } @Override public AutoValue_Amoeba[] newArray(int size) { return new AutoValue_Amoeba[size]; } };
If the generateCreator method has been changed as follows: -
FieldSpec generateCreator(ProcessingEnvironment env, TypeName autoValueType, List<Property> properties, TypeName type, Map<TypeMirror, FieldSpec> typeAdapters) { ClassName creator = ClassName.bestGuess("android.os.Parcelable.Creator"); TypeName creatorOfClass = ParameterizedTypeName.get(creator, autoValueType);
This method will then generate a Parcelable CREATOR that will look like this
public static final Parcelable.Creator<Amoeba> CREATOR = new Parcelable.Creator<Amoeba>() { @Override public AutoValue_Amoeba createFromParcel(Parcel in) { return new AutoValue_Amoeba( in.readString() ); } @Override public AutoValue_Amoeba[] newArray(int size) { return new AutoValue_Amoeba[size]; } };
This CREATOR now allows the TypeAdapter to use the CREATOR, as shown here.
class AmoebaTypeAdapter implements TypeAdapter<Set<Amoeba>> { @Override public Set<Amoeba> fromParcel(Parcel in) { final List<Amoeba> arrayList = new ArrayList<>(); in.readTypedList(arrayList, AutoValue_Amoeba.CREATOR); return new TreeSet<>(arrayList); } @Override public void toParcel(Set<Amoeba> value, Parcel dest) { final ArrayList<Amoeba> arrayList = new ArrayList<>(value); dest.writeTypedList(arrayList); } }