-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Add support for Optional<T> in parsing instead of null #2644
Comments
This is similar to #1005, or possibly a more specific duplicate of it. And related to #61. Currently when a property is not present in the JSON data, Gson does not modify the field of the Java object and does not call the As workaround you can initialize the field with a non- |
Thanks for providing this work around. I have had a go using it but this actually won't work in the Optional case. I can provide the stacktrace if you would like but I am reasonably confident from reading through it that when I specify I like the idea of providing a more general solution here, but I think there could be some advantages to implicitly using the |
Sorry, I should have mentioned that Gson has no built-in adapter for |
Ok I'll do that, thanks for the help! |
Problem solved by the feature
Often when parsing their is the risk of null exceptions and more importantly it is hard to document a field being optional through the type signature.
Feature description
This feature would support using Optional for fields where if GSON cannot find the key it would give the none variant.
The text was updated successfully, but these errors were encountered: