@Override
    public void encode(BsonWriter writer, T value, EncoderContext encoderContext) {
        writer.writeStartDocument();
        try {
            if (CodecPool.UPSERT_ENCODER_CONTEXT == encoderContext) {
                encodeValueForUpsert(writer, value, encoderContext);
            } else {
                encodeValue(writer, value, encoderContext);
            }
        } catch (Exception e) {
            throw new SerializationException(
                    "Failed to encode the entity of the class: "
                            + entity.entityClass()
                                    .getName(),
                    e);
        }
        writer.writeEndDocument();
    }
@author James Chen
@see org.bson.codecs.pojo.PojoCodecImpl
turms-server-common/src/main/java/im/turms/server/common/storage/mongo/codec/EntityCodec.java