我正在尝试使用 AutoValueGsonTypeAdapterFactory,但从未生成该类。这是我的实现。
@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"
typeAdapter 方法有一个警告“从未使用”并且从不生成 AutoValueGsonTypeAdapterFactory
最佳答案
似乎 AutoValueGsonTypeAdapterFactory
是自动生成的,直到版本 0.4.0。
现在建议的方法是为所有使用 @GsonTypeAdapterFactory
注释的 auto-value-gson
类创建一个 TypeAdapterFactory
实现.阅读 auto-value-gson
文档。
关于android - AutoValue Gson 扩展不创建 AutoValueGsonTypeAdapterFactory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41308947/