public function marshall($data, $output = Marshaller::MARSHALL_JSON)
    {
        if (is_null($data) === true) {
            $json = array('base' => $data);
        } elseif ($data instanceof State) {

            $json = array();

            foreach ($data as $variable) {
                $json[$variable->getIdentifier()] = $this->marshallUnit($variable->getValue());
            }
        } elseif ($data instanceof QtiDatatype) {
            $json = $this->marshallUnit($data);
        } else {
            $className = get_class($this);
            $msg = "The '${className}::marshall' method only takes State, QtiDatatype and null values as arguments, '";

            if (is_object($data) === true) {
                $msg .= get_class($data);
            } else {
                $msg .= gettype($data);
            }

            $msg .= "' given.";
            $code = MarshallingException::NOT_SUPPORTED;
            throw new MarshallingException($msg, $code);
        }

        return ($output === self::MARSHALL_JSON) ? json_encode($json) : $json;
    }