Skip to content

Commit c583f3a

Browse files
authored
Give a better hint to users
1 parent 426273e commit c583f3a

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,20 @@ protected function instantiateObject(array &$data, string $class, array &$contex
425425
throw $e;
426426
}
427427

428+
$message = $e->getMessage();
429+
430+
if (preg_match('/#\d+ \(([^)]+)\) must be of type ([,]+), ([,]+) given/', $message, $match)) {
431+
$message = sprintf(
432+
'The type of the "%s" parameter for class "%s" must be of type "%s" ("%s" given).',
433+
$match[1],
434+
$class,
435+
$match[2],
436+
$match[3],
437+
);
438+
}
439+
428440
$exception = NotNormalizableValueException::createForUnexpectedDataType(
429-
$e->getMessage(),
441+
$message,
430442
$data,
431443
[$class],
432444
$context['deserialization_path'] ?? null,

0 commit comments

Comments
 (0)