protected function createDataObjectFrom($value, $className)
    {
        // If the value is already the correct object, return it unaltered
        if ($value instanceof $className) {
            return $value;
        }

        // Convert object to array so it can be used to set  attributes in the DataObject
        if ($value instanceof Arrayable) {

            $value = $value->toArray();

        }  elseif (is_object($value)) {

            $value = json_decode(json_encode($value), true);
        }

        // Make validation fail if value could not be converted to an array
        if ( ! is_array($value)) {
            return false;
        }


        // Build an instance of the DataObject
        $dataObjectClass = $className;

        try {

            $dataObject = new $dataObjectClass($value);

        } catch (Throwable $e) {

            throw new InvalidArgumentException($dataObjectClass . ' is not instantiable as a DataObject', 0, $e);
        }

        if ( ! ($dataObject instanceof DataObjectInterface)) {

            throw new InvalidArgumentException($dataObjectClass . ' is not a validatable DataObject');
        }

        return $dataObject;
    }