bson/src/main/org/bson/BsonDocumentWrapper.java
@SuppressWarnings({"rawtypes", "unchecked"})
    public static BsonDocument asBsonDocument(final Object document, final CodecRegistry codecRegistry) {
        if (document == null) {
            return null;
        }
        if (document instanceof BsonDocument) {
            return (BsonDocument) document;
        } else {
            return new BsonDocumentWrapper(document, codecRegistry.get(document.getClass()));
        }
    }
@SuppressWarnings({"rawtypes", "unchecked"})
    public static BsonDocument asBsonDocument(final Object document, final CodecRegistry codecRegistry) {
        if (document == null) {
            return null;
        }
        if (document instanceof BsonDocument) {
            return (BsonDocument) document;
        } else {
            return new BsonDocumentWrapper(document, codecRegistry.get(document.getClass()));
        }
    }
A helper to convert an document of type Object to a BsonDocument

<p>If not already a BsonDocument it looks up the documents' class in the codecRegistry and wraps it into a BsonDocumentWrapper</p>

@param document      the document to convert
@param codecRegistry the codecRegistry that can be used in the conversion of the Object
@return a BsonDocument