InstantSerde implements Serde<String, Instant> { @Override public Instant deserialize(final String value) { try { return Instant.from( DateTimeFormatter.ISO_OFFSET_DATE_TIME.parse(value) ); } catch (final DateTimeParseException ex) { throw new IllegalArgumentException(ex); } }  @Override Instant deserialize(final String value); @Override String serialize(final Instant value);  }
@Test public void canDeserializeUtcIsoString() { final Instant instant = serde.deserialize("2019-06-01T09:42:55Z"); assertEquals(1559382175, instant.getEpochSecond()); assertEquals(0, instant.getNano()); }
@Test public void canDeserializeOffsetIsoString() { final Instant instant = serde.deserialize("2019-06-01T10:42:55+01:00"); assertEquals(1559382175, instant.getEpochSecond()); assertEquals(0, instant.getNano()); }
@Test public void canDeserializeSubSecondPrecisionUtcIsoString() { final Instant instant = serde.deserialize("2019-06-01T09:42:55.123Z"); assertEquals(1559382175, instant.getEpochSecond()); assertEquals(123000000, instant.getNano()); }
@Test public void failsParsingWithIllegalArgumentException() { assertThrows( IllegalArgumentException.class, () -> serde.deserialize("2019-06-01T09:42:55.12X3Z") ); }