private static BsonValue writeAndReturnValue(IoConsumer<BsonGenerator> consumer) throws IOException {
    BsonDocumentWriter writer = new BsonDocumentWriter(new BsonDocument());
    BsonGenerator generator = generatorFor(writer);
    generator.writeStartObject();
    generator.writeFieldName("value");
    consumer.accept(generator);
    generator.writeEndObject();
    BsonDocument doc = writer.getDocument();
    check(doc.keySet()).has("value");
    return doc.get("value");
  }
Writing null values does not cause an exception
criteria/mongo/test/org/immutables/criteria/mongo/bson4jackson/BsonGeneratorTest.java