ThreeTen-Backport-Gson-Adapter
ThreeTen-Backport-Gson-Adapter copied to clipboard
Simpler, customizable approach
Hi, you might want to take a simpler approach and create a TypeAdapter generator for TemporalAccessor implementations like so:
https://gist.github.com/baudm/1d403548f63012bc503ed61f7c4f61ca
I was thinking of packaging it as a library but it's too small, thus a gist.
The advantage of this approach is two-fold:
- Extremely small API (just 1 static method)
- Able to pass a custom DateTimeFormatter for serializing/deserializing the TemporalAccessor instance (which means that even if your backend doesn't follow conventions, you can still parse a valid date/time value into its corresponding type (e.g. LocalDate, ZonedDateTime).
Yeah, current implementation does have lots of duplicate code. Thanks for the idea!