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
Optionalsupport 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.ClassJsonAdapterandKotlinJsonAdapterfor supporting defaulting absent values toOptional.empty().Open questions:
a.
Optional<String>?b. Do we support this in code gen too?
j.u.Optionalor do we want to do something more generic (to support Guava, KOptional, etc)? How would that look if so?JsonAdapter.ifAbsent()or separateAbsenceHandlerinterface?