Add support to (de)serialize Ion timestamps with java.time classes #213
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
(continued from: #208 - since I switched branches I opened a different PR)
Adding support for some java 8
java.time
classes to (de)serialize to Ion's timestamp type.Starting with just the following since it seemed pretty clear cut that there could be support:
java.time.Instant
java.time.OffsetDateTime
java.time.ZonedDateTime
I was less sure about how to handle
java.time.LocalDate
andjava.time.LocalDateTime
so they have been omitted.Serialization is fairly straightforward, each class is pretty easily transformed into an Ion timestamp. The caveat is that the transformation for a
java.time.ZonedDateTime
will be slightly lossy since an Ion timestamp cannot represent the timezone, just the offset. In this case the local offset is used.Deserialization is also mostly straight forward. In the event that the Ion timestamp's time local offset is unknown (-00:00), then the default timezone is used from the context.
(De)serialization to/from an Ion int or Ion decimal is added as well though I haven't tried to add support to/from an Ion string.
Some of the code could be refined with lambdas and function references in the future if this module is moved to java 8.