protected function validateObject($value, ValidationField $field) {
        if (!$this->isArray($value) || isset($value[0])) {
            $field->addTypeError($value, 'object');
            return Invalid::value();
        } elseif (is_array($field->val('properties')) || null !== $field->val('additionalProperties')) {
            // Validate the data against the internal schema.
            $value = $this->validateProperties($value, $field);
        } elseif (!is_array($value)) {
            $value = $this->toObjectArray($value);
        }

        if (($maxProperties = $field->val('maxProperties')) && count($value) > $maxProperties) {
            $field->addError(
                'maxProperties',
                [
                    'messageCode' => 'This must contain no more than {maxProperties} {maxProperties,plural,item,items}.',
                    'maxItems' => $maxProperties,
                ]
            );
        }

        if (($minProperties = $field->val('minProperties')) && count($value) < $minProperties) {
            $field->addError(
                'minProperties',
                [
                    'messageCode' => 'This must contain at least {minProperties} {minProperties,plural,item,items}.',
                    'minItems' => $minProperties,
                ]
            );
        }

        return $value;
    }