@Test
  public void localDateTime() throws IOException {
    LocalDateTime now = LocalDateTime.now().truncatedTo(ChronoUnit.MILLIS);
    long epoch = now.toInstant(ZoneOffset.UTC).toEpochMilli();

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

    // read
    LocalDateTime date = adapter.read(Jsons.readerAt(new BsonDateTime(epoch)));
    LocalDateTime valueRead = Instant.ofEpochMilli(epoch).atOffset(ZoneOffset.UTC).toLocalDateTime();
    check(date).is(now);

    // write
    BsonValue bson = writeAndReadBson(valueRead);
    check(bson.getBsonType()).is(BsonType.DATE_TIME);
    check(Instant.ofEpochMilli(bson.asDateTime().getValue()).atOffset(ZoneOffset.UTC).toLocalDateTime()).is(valueRead);
  }
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