public function prepareAttributeValue($mapping, $value)
    {
        if ($value === null) {
            return Type::getNull();
        }

        $type = $mapping !== null ? $mapping->getType() : TypeFactory::getTypeFromPHPVariable($value);

        if (is_array($value)) {
            $value = array_map(
                function ($v) {
                    $this->prepareAttributeValue(null, $v);
                },
                $value
            );
        }

        return $type->convertToDatabaseValue($value);
    }