Skip to content
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

Closed
wants to merge 2 commits into from

Conversation

spacey-sooty
Copy link
Contributor

No description provided.

@ThadHouse
Copy link
Member

Does this actually work? Not sure if gson will actually parse this correctly.

@spacey-sooty
Copy link
Contributor Author

I was concerned about that as well, I'll mock up a test for it later

@spacey-sooty
Copy link
Contributor Author

This doesn't work, I've opened an issue google/gson#2644

Comment on lines +19 to +30
@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);
}
Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants