Comments (7)
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 sopublic 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.
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.
from auto-value-gson.
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-gson ※ Sorry, 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.
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.
@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.
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.
I see better now. Thank you for the follow.
from auto-value-gson.
Related Issues (20)
- Parse json object with varying data types
- RV_RETURN_VALUE_IGNORED findbugs error HOT 3
- Build failed in the generated read method for a generic class HOT 1
- Originating element not set HOT 3
- Generate proguard rules HOT 1
- Generic base types cause compile errors HOT 2
- Allow custom opt-in annotation for factory HOT 2
- AutoValueGsonExtension fails on immutable collections. HOT 1
- "Unable to get public no-arg constructor" simply when adding auto-value-gson dependency HOT 3
- auto-value-gson-from-rharter-generated-invalid-code HOT 6
- What dependency AutoValue annotation is in ? HOT 1
- Non-deterministic generation of TypeAdapterFactory HOT 2
- Issue using @GenerateTypeAdapter with maven HOT 2
- `@Nullable` doesn't work correctly with nested types
- NullPointerException processing ImmutableList.Builder Builder method
- Compilation error in Eclipse/maven
- Handling unrecognized json properties HOT 1
- @AutoValue.Builder generates objects with all fields HOT 2
- 也许这个方案更加好 HOT 1
- Could not instantiate annotation processor 'com.ryanharter.auto.value.gson.AutoValueGsonAdapterFactoryProcessor'
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from auto-value-gson.