private void bsonThenJackson(String json) throws IOException {
    ObjectNode toWrite = maybeWrap(mapper.readTree(json));

    BasicOutputBuffer buffer = new BasicOutputBuffer();
    BsonWriter writer = new BsonBinaryWriter(buffer);

    // write with BSON
    BsonDocument expected = BsonDocument.parse(toWrite.toString());
    MongoClientSettings.getDefaultCodecRegistry().get(BsonDocument.class)
            .encode(writer, expected, EncoderContext.builder().build());

    BsonBinaryReader reader = new BsonBinaryReader(ByteBuffer.wrap(buffer.toByteArray()));
    IOContext ioContext = new IOContext(new BufferRecycler(), ContentReference.unknown(), false);
    BsonParser parser = new BsonParser(ioContext, 0, reader);

    // read with jackson
    BsonDocument actual = BsonDocument.parse(mapper.readValue(parser, JsonNode.class).toString());

    if (!actual.equals(expected)) {
       check(maybeUnwrap(actual)).is(maybeUnwrap(expected));
       Assertions.fail("Should have failed before");
    }
  }
write with BSON read with jackson.
inverse of {@link #jacksonThenBson(String)}
criteria/mongo/test/org/immutables/criteria/mongo/bson4jackson/BsonParserTest.java