-
Notifications
You must be signed in to change notification settings - Fork 761
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
Prototype support for handling absence #1412
base: master
Are you sure you want to change the base?
Conversation
Pushed an absence handler API demo instead, which I think came out pretty clean all things considered! |
Should say I'm not thrilled about the of adding this directly to the JsonAdapter API, but without a clear/easy way to access delegated adapters it's not clear how to unpack an opt-in interface's APIs |
In Kotlin I'd use this to fall back to any default arguments on data classes. In our existing implementation this is achieved via a work around utilising a custom |
@lassem we already do that in kotlin. This would only be for Java or for kotlin cases where you don't provide a default and simply want it to coerce to Optional.empty() |
That is true. However, the aforementioned |
I don't see how it would since an absent key would not be present in a map. In any case let's keep this PR on topic |
(edit: see following comments, this was generalized away from just Optional)
This is a prototype of what
Optional
support would look like. This implements it in two parts:OptionalJsonAdapter
+ associated factory. This essentially works by associating nulls withOptional.absent()
and used for properties that are either present or explicitlynull
.ClassJsonAdapter
andKotlinJsonAdapter
for supporting defaulting absent values toOptional.empty()
.Open questions:
a.
Optional<String>?
b. Do we support this in code gen too?
j.u.Optional
or do we want to do something more generic (to support Guava, KOptional, etc)? How would that look if so?JsonAdapter.ifAbsent()
or separateAbsenceHandler
interface?