diff --git a/src/Symfony/Component/Serializer/Normalizer/UidNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/UidNormalizer.php index 91e8c1cd4a150..81e60a3494537 100644 --- a/src/Symfony/Component/Serializer/Normalizer/UidNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/UidNormalizer.php @@ -71,10 +71,8 @@ public function denormalize($data, string $type, string $format = null, array $c { try { return AbstractUid::class !== $type ? $type::fromString($data) : Uuid::fromString($data); - } catch (\InvalidArgumentException $exception) { - throw NotNormalizableValueException::createForUnexpectedDataType('The data is not a valid UUID string representation.', $data, [Type::BUILTIN_TYPE_STRING], $context['deserialization_path'] ?? null, true); - } catch (\TypeError $exception) { - throw NotNormalizableValueException::createForUnexpectedDataType('The data is not a valid UUID string representation.', $data, [Type::BUILTIN_TYPE_STRING], $context['deserialization_path'] ?? null, true); + } catch (\InvalidArgumentException|\TypeError $exception) { + throw NotNormalizableValueException::createForUnexpectedDataType(sprintf('The data is not a valid "%s" string representation.', $type), $data, [Type::BUILTIN_TYPE_STRING], $context['deserialization_path'] ?? null, true); } catch (\Error $e) { if (str_starts_with($e->getMessage(), 'Cannot instantiate abstract class')) { return $this->denormalize($data, AbstractUid::class, $format, $context); diff --git a/src/Symfony/Component/Serializer/Tests/SerializerTest.php b/src/Symfony/Component/Serializer/Tests/SerializerTest.php index 0d4c8700d432c..5fc511dc8a715 100644 --- a/src/Symfony/Component/Serializer/Tests/SerializerTest.php +++ b/src/Symfony/Component/Serializer/Tests/SerializerTest.php @@ -884,7 +884,7 @@ public function testCollectDenormalizationErrors() ], 'path' => 'uuid', 'useMessageForUser' => true, - 'message' => 'The data is not a valid UUID string representation.', + 'message' => 'The data is not a valid "Symfony\Component\Uid\Uuid" string representation.', ], [ 'currentType' => 'null',