@Test
  public void instant() throws IOException {
    Instant now = Instant.now().truncatedTo(ChronoUnit.MILLIS);
    long epoch = now.toEpochMilli();

    TypeAdapter<Instant> adapter = gson.getAdapter(Instant.class);

    // read
    Instant date = adapter.read(Jsons.readerAt(new BsonDateTime(epoch)));
    check(date).is(now);

    // write
    BsonValue bson = writeAndReadBson(now);
    check(bson.getBsonType()).is(BsonType.DATE_TIME);
    check(Instant.ofEpochMilli(bson.asDateTime().getValue())).is(now);
  }
Tests that {@code java.time.*} and {@link Date} BSON codecs are properly working with Gson type adapters.
mongo/test/org/immutables/mongo/bson4gson/JavaTimeTest.java