diff --git a/Validator/RecursiveContextualValidator.php b/Validator/RecursiveContextualValidator.php index b1f1384ff..7920a07c8 100644 --- a/Validator/RecursiveContextualValidator.php +++ b/Validator/RecursiveContextualValidator.php @@ -649,8 +649,10 @@ private function validateGenericNode($value, ?object $object, ?string $cacheKey, return; } - // If the value is a scalar, pass it anyway, because we want - // a NoSuchMetadataException to be thrown in that case + if (!\is_object($value)) { + throw new NoSuchMetadataException(sprintf('Cannot create metadata for non-objects. Got: "%s".', \gettype($value))); + } + $this->validateObject( $value, $propertyPath,