ThreeTen-Backport-Gson-Adapter icon indicating copy to clipboard operation
ThreeTen-Backport-Gson-Adapter copied to clipboard

Simpler, customizable approach

Open baudm opened this issue 8 years ago • 1 comments

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:

  1. Extremely small API (just 1 static method)
  2. 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).

baudm avatar Oct 23 '16 15:10 baudm

Yeah, current implementation does have lots of duplicate code. Thanks for the idea!

aaronweihe avatar Oct 27 '16 07:10 aaronweihe