-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generated TypeAdapterFactory and null safety #50
Comments
You could submit a PR if you've got the code. Otherwise I'll have to add that. |
Are you saying that we should attach Also, there's this PR #23 that presumably eliminates the need to use |
Below is a quick solution for anyone else that hits this before #23 is completed. @GsonTypeAdapterFactory
public abstract class AutoValueAdapterFactory implements TypeAdapterFactory {
public static TypeAdapterFactory create() {
final TypeAdapterFactory factory = new AutoValueGson_AutoValueAdapterFactory();
return new TypeAdapterFactory() {
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
TypeAdapter<T> typeAdapter = factory.create(gson, type);
return typeAdapter != null ? typeAdapter.nullSafe() : null;
}
};
}
} |
@jachenry Thanks, I've been doing the same. |
Hi @jachenry Please can you explain to me with more details.. I have my factory like this: public class AutoValueGsonTyeAdapterFactory implements TypeAdapterFactory {
} Then I have your abstract class that contains my class @GsonTypeAdapterFactory
} And finally I need to call this classes in my GsonConverterFactory, but in this point I really don't now how to call the abstract class... public static GsonConverterFactory gsonConverterFactory = GsonConverterFactory.create( Can you help me in this last step? |
@jjimenez0611 You'll want to call the static
|
@jachenry, thanks I really appreciate your help, now I understand. |
This closes rharter#23, rharter#50 and rharter#67
This closes rharter#23, rharter#50 and rharter#67
This closes rharter#23, rharter#50 and rharter#67
Closed by #78 |
As of 0.2.5, My custom AutoValueTypeAdapterFactory would call
nullSafe()
on every type adapter I return in thecreate()
method. Refer #28 (comment).Beginning from 0.3.0, the generated AutoValueGsonTypeAdapterFactory does not call
nullSafe()
by default, which is the appropriate way for sure.So, how'd I go about ensuring null-safety when using the generated TypeAdapterFactory.
The text was updated successfully, but these errors were encountered: