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

    BasicOutputBuffer buffer = new BasicOutputBuffer();
    BsonWriter writer = new BsonBinaryWriter(buffer);
    BsonGenerator generator = new BsonGenerator(0, writer);
    // write with jackson
    mapper.writeValue(generator, toWrite);
    BsonBinaryReader reader = new BsonBinaryReader(ByteBuffer.wrap(buffer.toByteArray()));

    // read with BSON
    BsonDocument actual = MongoClientSettings.getDefaultCodecRegistry()
            .get(BsonDocument.class)
            .decode(reader, DecoderContext.builder().build());

    // compare results
    BsonDocument expected = BsonDocument.parse(toWrite.toString());
    if (!expected.equals(actual)) {
      check(maybeUnwrap(actual)).is(maybeUnwrap(expected));
      Assertions.fail("Should have failed before");
    }
  }
write with Jackson read with Bson.
Inverse of {@link #bsonThenJackson(String)}
criteria/mongo/test/org/immutables/criteria/mongo/bson4jackson/BsonParserTest.java