Giter VIP home page Giter VIP logo

Comments (7)

rharter avatar rharter commented on July 20, 2024 1

Ahh, yes, this is actually how it's designed to work. Unfortunately,
without that static factory method in the class, there's no way for the
type adapter factory to access the generated package private type adapter
reliably (we can't guarantee your factory is in the same package as all of
your models).

We've been talking about a reflection based solution for this, but for now
all of your AutoValue annotated classes need static type adapter methods.

On Sun, Sep 25, 2016, 8:13 AM Benoît Quenaudon [email protected]
wrote:

So I got it working but I am not sure I should be satisfied with the step
I took.

You can see here
https://github.com/sandboxing/testing-auto-value-gson/commits/master
the only difference between the failing and fixed build.

Basically, if I, in an other class, created a static typeAdapter creator
as so

public static TypeAdapter<Foo> typeAdapter(Gson gson) {
    return new AutoValue_Foo.GsonTypeAdapter(gson);
}

Then, the @GsonTypeAdapterFactory would generate the Factory constructor
as expected, but I wanted to the use @GsonTypeAdapterFactory so I would
not have to set the typeAdapter for every class.

Isn't it a bug?


You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub
#69 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABPJbqXRN6jCnqOHciVuj2ld55F-uSOOks5qtnN-gaJpZM4KD6YM
.

from auto-value-gson.

rharter avatar rharter commented on July 20, 2024

Looks fine to me. Have you built the project? When you first write it it will show up as unfound because it doesn't get generated until you build.

screen shot 2016-09-22 at 8 59 01 am

from auto-value-gson.

oldergod avatar oldergod commented on July 20, 2024

I had working after building this project, thanks a lot.

However, I cannot have it working on my project. I tried to isolate as much as I could here: https://github.com/sandboxing/testing-auto-value-gsonSorry, I should have done it the first time

I get the following error when I try to build the project (./gradlew build) and I cannot find out what is missing here

app/src/main/java/autovalue/testing/oldering/io/myapplication/AutoValueGsonTypeAdapterFactory.java:9: error: cannot find symbol
        return new AutoValueGson_AutoValueGsonTypeAdapterFactory();
                   ^
  symbol:   class AutoValueGson_AutoValueGsonTypeAdapterFactory
  location: class AutoValueGsonTypeAdapterFactory
1 error
:app:compileDebugJavaWithJavac FAILED

from auto-value-gson.

oldergod avatar oldergod commented on July 20, 2024

Confirmed on a CircleCI build to be sure it was a local problem. https://circleci.com/gh/sandboxing/testing-auto-value-gson/5

from auto-value-gson.

oldergod avatar oldergod commented on July 20, 2024

@rharter You must have a lot on your plate and I know I screwed up not showing the minimised version of my project at first but I would really appreciate any help finding what is missing in my configuration.

from auto-value-gson.

oldergod avatar oldergod commented on July 20, 2024

So I got it working but I am not sure I should be satisfied with the step I took.

You can see here the only difference between the failing and fixed build.

Basically, if I, in an other class, created a static typeAdapter creator as so

    public static TypeAdapter<Foo> typeAdapter(Gson gson) {
        return new AutoValue_Foo.GsonTypeAdapter(gson);
    }

Then, the @GsonTypeAdapterFactory would generate the Factory constructor as expected, but I wanted to the use @GsonTypeAdapterFactory so I would not have to set the typeAdapter for every class.

The generated code is below. Why would it depend on Foo if "auto-value-gson can create a single TypeAdapterFactory so that [I] don't have to add each generated TypeAdapter to [my] Gson instance manually."

public final class AutoValueGson_AutoValueGsonTypeAdapterFactory extends AutoValueGsonTypeAdapterFactory {
  @Override
  @SuppressWarnings("unchecked")
  public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
    Class<T> rawType = (Class<T>) type.getRawType();
    if (Foo.class.isAssignableFrom(rawType)) {
      return (TypeAdapter<T>) Foo.typeAdapter(gson);
    } else {
      return null;
    }
  }
}

Isn't there something wrong or am I misunderstanding its usage?

from auto-value-gson.

oldergod avatar oldergod commented on July 20, 2024

I see better now. Thank you for the follow.

from auto-value-gson.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.