rharter / auto-value-gson

AutoValue Extension to add Gson De/Serializer support
Apache License 2.0
603 stars 103 forks source link

MyClass_GsonTypeAdapter references non-existent intermediary AutoValue_MyClass class #222

Closed benwicks closed 5 years ago

benwicks commented 5 years ago

According to the documentation for @GenerateTypeAdapter:

When this annotation is used, there will be no intermediate AutoValue class generated (as opposed to the default logic, which generates an intermediate class and generates the TypeAdapter as a static inner class of it).

And according to the PR #160:

If the annotation is present, no intermediary AutoValue class will be generated either.

I am getting the following error on the generated type adapter when building my project:

MyClass_GsonTypeAdapter.java:140: error: AutoValue_MyClass(Long,String,String,String) has private access in AutoValue_MyClass
    return new AutoValue_MyClass(id, body, subject, type);
           ^

What is strange is that the non-existent AutoValue_MyClass class is referenced in the generated type adapter constructor earlier in the file but no error is thrown for that:

this.realFieldNames = Util.renameFields(AutoValue_MyClass.class, fields, gson.fieldNamingStrategy());

MyClass looks like this:

@GenerateTypeAdapter
@AutoValue
public abstract class MyClass {
...
    public static TypeAdapter<MyClass> typeAdapter(Gson gson) {
        return new MyClass_GsonTypeAdapter(gson);
    }
...
}

Is there something I'm doing incorrectly that this is getting generated to reference a non-existent class? Or do you know of a fix?

benwicks commented 5 years ago

My solution for now is just to convert the affected classes to kotlin data classes.