// Path: src/main/java/me/welkinbai/bsonmapper/Utils.java
// public static void checkIsSupportClazz(Class<?> targetClazz, String message) {
//     if (BsonValueConverterRepertory.isValueSupportClazz(targetClazz)) {
//         throw new BsonMapperConverterException(message);
//     }
// }
// 
// Path: src/main/java/me/welkinbai/bsonmapper/Utils.java
// public static void checkNotNull(Object object, String message) {
//     if (object == null) {
//         throw new NullPointerException(message);
//     }
// }
// 
// Path: src/main/java/me/welkinbai/bsonmapper/Utils.java
// public static boolean isStrEmpty(String str) {
//     return str == null || str.length() == 0;
// }


import org.bson.BsonBinaryReader;
import org.bson.BsonBinaryWriter;
import org.bson.BsonBinaryWriterSettings;
import org.bson.BsonDocument;
import org.bson.BsonValue;
import org.bson.BsonWriter;
import org.bson.BsonWriterSettings;
import org.bson.Document;
import org.bson.codecs.DocumentCodec;
import org.bson.codecs.configuration.CodecRegistries;
import org.bson.io.BasicOutputBuffer;
import org.bson.io.BsonInput;
import org.bson.io.BsonOutput;
import org.bson.json.JsonReader;
import org.bson.json.JsonWriter;
import org.bson.json.JsonWriterSettings;
import java.io.StringWriter;
import java.nio.ByteBuffer;
import java.util.Map.Entry;
import static me.welkinbai.bsonmapper.Utils.checkIsSupportClazz;
import static me.welkinbai.bsonmapper.Utils.checkNotNull;
import static me.welkinbai.bsonmapper.Utils.isStrEmpty;
    }

    @Override
    public Document writeToMongoDocument(Object obj) {
        if (obj == null) {
            return null;
        }
        BsonDocument bsonDocument = new BsonDocument();
        BsonValueConverterRepertory.getBsonDocumentConverter().encode(bsonDocument, obj, bsonMapperConfig);
        Document document = new Document();
        for (Entry<String, BsonValue> entry : bsonDocument.entrySet()) {
            document.put(entry.getKey(), entry.getValue());
        }
        return document;
    }

    @Override
    public BsonOutput writeToBsonOutput(Object object) {
        if (object == null) {
            return null;
        }
        BsonOutput bsonOutput = new BasicOutputBuffer();
        BsonWriter bsonBinaryWriter = new BsonBinaryWriter(new BsonWriterSettings(bsonMapperConfig.getMaxMapperLayerNum()),
                new BsonBinaryWriterSettings(bsonMapperConfig.getMaxDocumentSizeForBsonWriter()), bsonOutput);
        BsonValueConverterRepertory.getBsonDocumentConverter().encode(bsonBinaryWriter, object);
        return bsonOutput;
    }

    @Override
    public String writeAsJsonStr(Object object) {
// Path: src/main/java/me/welkinbai/bsonmapper/Utils.java
// public static void checkIsSupportClazz(Class<?> targetClazz, String message) {
//     if (BsonValueConverterRepertory.isValueSupportClazz(targetClazz)) {
//         throw new BsonMapperConverterException(message);
//     }
// }
// 
// Path: src/main/java/me/welkinbai/bsonmapper/Utils.java
// public static void checkNotNull(Object object, String message) {
//     if (object == null) {
//         throw new NullPointerException(message);
//     }
// }
// 
// Path: src/main/java/me/welkinbai/bsonmapper/Utils.java
// public static boolean isStrEmpty(String str) {
//     return str == null || str.length() == 0;
// }


// Path: src/main/java/me/welkinbai/bsonmapper/DefaultBsonMapper.java
import org.bson.BsonBinaryReader;
import org.bson.BsonBinaryWriter;
import org.bson.BsonBinaryWriterSettings;
import org.bson.BsonDocument;
import org.bson.BsonValue;
import org.bson.BsonWriter;
import org.bson.BsonWriterSettings;
import org.bson.Document;
import org.bson.codecs.DocumentCodec;
import org.bson.codecs.configuration.CodecRegistries;
import org.bson.io.BasicOutputBuffer;
import org.bson.io.BsonInput;
import org.bson.io.BsonOutput;
import org.bson.json.JsonReader;
import org.bson.json.JsonWriter;
import org.bson.json.JsonWriterSettings;
import java.io.StringWriter;
import java.nio.ByteBuffer;
import java.util.Map.Entry;
import static me.welkinbai.bsonmapper.Utils.checkIsSupportClazz;
import static me.welkinbai.bsonmapper.Utils.checkNotNull;
import static me.welkinbai.bsonmapper.Utils.isStrEmpty;

    }

    @Override
    public Document writeToMongoDocument(Object obj) {
        if (obj == null) {
            return null;
        }
        BsonDocument bsonDocument = new BsonDocument();
        BsonValueConverterRepertory.getBsonDocumentConverter().encode(bsonDocument, obj, bsonMapperConfig);
        Document document = new Document();
        for (Entry<String, BsonValue> entry : bsonDocument.entrySet()) {
            document.put(entry.getKey(), entry.getValue());
        }
        return document;
    }

    @Override
    public BsonOutput writeToBsonOutput(Object object) {
        if (object == null) {
            return null;
        }
        BsonOutput bsonOutput = new BasicOutputBuffer();
        BsonWriter bsonBinaryWriter = new BsonBinaryWriter(new BsonWriterSettings(bsonMapperConfig.getMaxMapperLayerNum()),
                new BsonBinaryWriterSettings(bsonMapperConfig.getMaxDocumentSizeForBsonWriter()), bsonOutput);
        BsonValueConverterRepertory.getBsonDocumentConverter().encode(bsonBinaryWriter, object);
        return bsonOutput;
    }

    @Override
    public String writeAsJsonStr(Object object) {
        if (object == null) {