@Test
  public void javaUtilDateUsingGson() throws IOException {

    Gson gsonWithInternalDateTypeAdapter = GsonCodecs.newGsonWithBsonSupport(new Gson());

    TypeAdapter<Date> adapter = gsonWithInternalDateTypeAdapter.getAdapter(Date.class);

    Date now = Date.from(Instant.now().truncatedTo(ChronoUnit.SECONDS));

    // write
    BsonValue bson = writeAndReadBsonUsingGson(now, gsonWithInternalDateTypeAdapter);
    check(bson.getBsonType()).is(BsonType.STRING);
    String dateAsString = bson.asString().getValue();
    check(dateAsString).isNonEmpty();

    // read
    Date date = adapter.read(Jsons.readerAt(new BsonString(dateAsString)));
    check(date).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