-
Notifications
You must be signed in to change notification settings - Fork 22
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
account for jsonUrl being null in type signature #193
Conversation
Does this actually work? Not sure if gson will actually parse this correctly. |
I was concerned about that as well, I'll mock up a test for it later |
This doesn't work, I've opened an issue google/gson#2644 |
@SuppressWarnings("unchecked") | ||
@Override | ||
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) { | ||
Class<T> rawType = (Class<T>) type.getRawType().getClass(); | ||
if (rawType != Optional.class) { | ||
return null; | ||
} | ||
final ParameterizedType parameterizedType = (ParameterizedType) type.getType(); | ||
final Type actualType = parameterizedType.getActualTypeArguments()[0]; | ||
final TypeAdapter<?> adapter = gson.getAdapter(TypeToken.get(actualType)); | ||
return new OptionalTypeAdapter(adapter); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should allow us to parse Optional correctly but has a few warnings to do with unchecked casts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t think that is worth adding, for something we don’t really need anyway. Empty string is just fine and we can specify that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll open a new pr to default it to an empty string and close this one
No description provided.