protected function marshallUnit($unit)
    {
        if (is_null($unit) === true) {
            $json = array('base' => null);
        } elseif ($unit instanceof QtiScalar) {
            $json = $this->marshallScalar($unit);
        } elseif ($unit instanceof MultipleContainer) {
            $json = array();
            $strBaseType = BaseType::getNameByConstant($unit->getBaseType());
            $json['list'] = array($strBaseType => array());

            foreach ($unit as $u) {
                $data = $this->marshallUnit($u);
                $json['list'][$strBaseType][] = $data['base'][$strBaseType];
            }
        } elseif ($unit instanceof RecordContainer) {
            $json = array();
            $json['record'] = array();

            foreach ($unit as $k => $u) {
                $data = $this->marshallUnit($u);
                $jsonEntry = array();
                $jsonEntry['name'] = $k;

                if (array_key_exists('base', $data) === true) {
                    // Primitive base type.
                    $jsonEntry['base'] = $data['base'];
                } else {
                    // A nested list.
                    $jsonEntry['list'] = $data['list'];
                }

                $json['record'][] = $jsonEntry;
            }
        } else {
            $json = $this->marshallComplex($unit);
        }

        return $json;
    }