rharter / auto-value-parcel

An Android Parcelable extension for Google's AutoValue.
Apache License 2.0
655 stars 64 forks source link

JavaBeans-style name prefixes stop working when implementing Parcelable #47

Closed 3flex closed 6 years ago

3flex commented 8 years ago

I have a class that has both AutoValue and your AutoValue Gson Extension enabled and working well. The class uses JavaBeans-style name prefixes.

When I try to make the class Parcelable the JavaBeans-style prefixes stop working. The GSON extension starts using the field name including the JavaBeans prefix (in generated source I see jsonWriter.name("getName");) instead of stripping it like it does without Parcelable (jsonWriter.name("name");)

Let me know if I can provide any additional information. It should be easy enough to see what's going on using this minimal class and toggling implements Parcelable on and off:

@AutoValue
public abstract class Test implements Parcelable {

    public abstract String getName();

    public static TypeAdapterFactory typeAdapterFactory() {
        return AutoValue_Test.typeAdapterFactory();
    }
}

From gradle.build:

    apt 'com.google.auto.value:auto-value:1.2'
    provided 'com.google.auto.value:auto-value:1.2'
    apt 'com.ryanharter.auto.value:auto-value-gson:0.2.2'
    apt 'com.ryanharter.auto.value:auto-value-parcel:0.2.1'
gabrielittner commented 8 years ago

It's a general AutoValue issue with consumed properties. Get/is will only be removed from the name if all methods use them, but when AutoValue checks if that is the case it will see int describeContents(). Therefor it thinks not all properties use get/is as prefix and doesn't strip them from the name.

As a workaround you can implement describeContents() yourself:

public int describeContents() {
    return 0;
}
JakeWharton commented 7 years ago

Is this still an issue?