rharter / auto-value-gson

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

Error on usage of GsonTypeAdapterFactory when there are no generated TypeAdapters. #171

Closed NightlyNexus closed 5 years ago

NightlyNexus commented 6 years ago

I was adding a @GsonTypeAdapterFactory today and couldn't figure out why my AutoValueGson_JsonAdapterFactory was not being generated.

@GsonTypeAdapterFactory
public abstract class JsonAdapterFactory implements TypeAdapterFactory {
  public static TypeAdapterFactory create() {
    return new AutoValueGson_JsonAdapterFactory();
  }
}

I later realized that none of my AV models (which are themselves generated by another tool), had included the static jsonAdapter(Gson gson) methods.

Would it be possible to check for @GsonTypeAdapterFactory usage when there is no TypeAdapterFactory to generate? (same question for av-moshi.)

rharter commented 6 years ago

Is there no warning emitted? I thought we had done that a while ago (on the phone, so hard to double check)

On Thu, Mar 1, 2018, 12:41 PM Eric Cochran notifications@github.com wrote:

I was adding a @GsonTypeAdapterFactory today and couldn't figure out why my AutoValueGson_JsonAdapterFactory was not being generated.

@GsonTypeAdapterFactorypublic abstract class JsonAdapterFactory implements TypeAdapterFactory { public static TypeAdapterFactory create() { return new AutoValueGson_JsonAdapterFactory(); } }

I later realized that none of my AV models (which are themselves generated by another tool), had included the static jsonAdapter(Gson gson) methods.

Would it be possible to check for @GsonTypeAdapterFactory usage when there is no TypeAdapterFactory to generate? (same question for av-moshi.)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/rharter/auto-value-gson/issues/171, or mute the thread https://github.com/notifications/unsubscribe-auth/ABPJbv2MRD75N0w6gMWcAd-gUx8IO0Q8ks5taHkKgaJpZM4SZHP- .

okorz001 commented 6 years ago

I ran into this problem today. There is no specific warning emitted from auto-value-gson. The compiler will just complain that the generated class does not exist (cannot find symbol).

I did not realize that I still needed to add the static TypeAdapter methods to every class when using the GsonTypeAdapterFactory until I saw this issue.

Andranik-Asilbekyan commented 6 years ago

Today I got the same error(AutoValueGson_MyAdapterFactory was not generated).

`@GsonTypeAdapterFactory public abstract class MyAdapterFactory implements TypeAdapterFactory {

public static TypeAdapterFactory create() {
    return new AutoValueGson_MyAdapterFactory();
}

} Error log: Caused by: java.lang.NoClassDefFoundError: com/google/auto/value/AutoValue at com.ryanharter.auto.value.gson.AutoValueGsonAdapterFactoryProcessor.getSupportedAnnotationTypes(AutoValueGsonAdapterFactoryProcessor.java:61) .... Caused by: java.lang.ClassNotFoundException: com.google.auto.value.AutoValue `

nksaroj commented 6 years ago

java.lang.NoClassDefFoundError: com/google/auto/value/AutoValue same here. Has any one figured out the workaround ?

liujoshua commented 6 years ago

Hello, I think I may have found a fix for one case. When using multiple, interdependent modules with @AutoValue classes, I was also seeing java.lang.NoClassDefFoundError: com/google/auto/value/AutoValue

Here's what I changed

   annotationProcessor 'com.ryanharter.auto.value:auto-value-gson:0.7.0'
   annotationProcessor 'com.google.auto.value:auto-value-annotations:1.6' // include again for auto-value-gson

Here was my project dependency structure :app (has autovalues) -> :ui -> :presentation -> :domain (has autovalues). The problem appeared when adding auto-value-gson to :app

Not sure why this is happening! I see that auto-value-gson already includes auto-value-annotations as an API dependency: https://github.com/rharter/auto-value-gson/blob/a264e19063f271f7166ea59b0202f78b854342f1/auto-value-gson/build.gradle#L14

@nksaroj @Andranik-Asilbekyan

jffiorillo commented 6 years ago

@liujoshua (or anyone) know why adding the auto-value-annotations as annotationProcessor solve the issue ?

okmanideep commented 6 years ago

why is this added as an api dependency for the annotationProcessor? https://github.com/rharter/auto-value-gson/blob/a264e19063f271f7166ea59b0202f78b854342f1/auto-value-gson/build.gradle#L13

jffiorillo commented 6 years ago

@okmanideep It contains the interfaces ( ex: @interface AutoValue ) to be used by the annotationProcessor.

francais-harry commented 6 years ago

Not sure but maybe related topic? https://github.com/rharter/auto-value-moshi/issues/106

zsweigart commented 6 years ago

This also fails when you have the autovalue classes in a different module than your type adapter