AutoValue Gson Extension not creating AutoValueGsonTypeAdapterFactory

1k views Asked by At

I'm trying to use AutoValueGsonTypeAdapterFactory but the class is never generated. Here is my implementation.

@AutoValue
public abstract class Foo {
    public abstract String bar();
    @SerializedName("Baz") abstract String baz();
    public abstract int quux();
    public static TypeAdapter<Foo> typeAdapter(Gson gson) {
        return new AutoValue_Foo.GsonTypeAdapter(gson);
   }
}

//Gson
compile "com.google.code.gson:gson:2.8.0"
//AutoValue
apt "com.google.auto.value:auto-value:1.3"
apt "com.ryanharter.auto.value:auto-value-gson:0.4.5"
provided "com.ryanharter.auto.value:auto-value-gson:0.4.5"

The typeAdapter method has a warning "never used" and AutoValueGsonTypeAdapterFactory is never generated

2

There are 2 answers

0
Marco Righini On BEST ANSWER

Seems that the AutoValueGsonTypeAdapterFactory is autogenerated until version 0.4.0.

Now the suggested approach is to create a single implementation of TypeAdapterFactory for all of your auto-value-gson classes annotated with @GsonTypeAdapterFactory. Read the auto-value-gson docs.

0
rharter On

AutoValue: Gson Extension now requires that you annotate a class with @GsonTypeAdapterFactory since the auto generating solution didn't support multiple module projects.

You can find the details in the documentation.