/// <inheritdoc />
        public override object Deserialize(byte[] serializedBytes, Type type)
        {
            new { type }.Must().NotBeNull();

            this.InternalBsonThrowOnUnregisteredTypeIfAppropriate(type);

            if (serializedBytes == null)
            {
                return(null);
            }

            return(NaosBsonSerializerHelper.Deserialize(serializedBytes, type));
        }
        /// <inheritdoc />
        public override T Deserialize <T>(byte[] serializedBytes)
        {
            var objectType = typeof(T);

            this.InternalBsonThrowOnUnregisteredTypeIfAppropriate(objectType);

            if (serializedBytes == null)
            {
                return(default(T));
            }

            return(NaosBsonSerializerHelper.Deserialize <T>(serializedBytes));
        }
        /// <inheritdoc />
        public override byte[] SerializeToBytes(object objectToSerialize)
        {
            var objectType = objectToSerialize?.GetType();

            this.InternalBsonThrowOnUnregisteredTypeIfAppropriate(objectType);

            if (objectToSerialize == null)
            {
                return(null);
            }

            return(NaosBsonSerializerHelper.SerializeToBytes(objectToSerialize));
        }
        /// <inheritdoc />
        public override object Deserialize(string serializedString, Type type)
        {
            new { type }.Must().NotBeNull();

            this.InternalBsonThrowOnUnregisteredTypeIfAppropriate(type);

            if (serializedString == SerializationConfigurationBase.NullSerializedStringValue)
            {
                return(null);
            }

            var document = serializedString.ToBsonDocument();

            return(NaosBsonSerializerHelper.DeserializeFromDocument(document, type));
        }
        /// <inheritdoc />
        public override T Deserialize <T>(string serializedString)
        {
            var objectType = typeof(T);

            this.InternalBsonThrowOnUnregisteredTypeIfAppropriate(objectType);

            if (serializedString == SerializationConfigurationBase.NullSerializedStringValue)
            {
                return(default(T));
            }

            var document = serializedString.ToBsonDocument();

            return(NaosBsonSerializerHelper.DeserializeFromDocument <T>(document));
        }
        /// <inheritdoc />
        public override string SerializeToString(object objectToSerialize)
        {
            var objectType = objectToSerialize?.GetType();

            this.InternalBsonThrowOnUnregisteredTypeIfAppropriate(objectType);

            if (objectToSerialize == null)
            {
                return(SerializationConfigurationBase.NullSerializedStringValue);
            }

            var document = NaosBsonSerializerHelper.SerializeToDocument(objectToSerialize);
            var json     = document.ToJson();

            return(json);
        }