diff --git a/src/Symfony/Component/Serializer/CHANGELOG.md b/src/Symfony/Component/Serializer/CHANGELOG.md index fdefebdc07e58..56ed3863c4c79 100644 --- a/src/Symfony/Component/Serializer/CHANGELOG.md +++ b/src/Symfony/Component/Serializer/CHANGELOG.md @@ -4,6 +4,7 @@ CHANGELOG 6.4 --- + * Add `TranslatableNormalizer` * Allow `Context` attribute to target classes * Deprecate Doctrine annotations support in favor of native attributes * Allow the `Groups` attribute/annotation on classes diff --git a/src/Symfony/Component/Serializer/Normalizer/TranslatableNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/TranslatableNormalizer.php index b79a0ffb99488..a4aef51f8cea9 100644 --- a/src/Symfony/Component/Serializer/Normalizer/TranslatableNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/TranslatableNormalizer.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Serializer\Normalizer; use Symfony\Component\Serializer\Exception\InvalidArgumentException; +use Symfony\Component\Serializer\Exception\NotNormalizableValueException; use Symfony\Contracts\Translation\TranslatableInterface; use Symfony\Contracts\Translation\TranslatorInterface; @@ -36,7 +37,7 @@ public function __construct( public function normalize(mixed $object, string $format = null, array $context = []): string { if (!$object instanceof TranslatableInterface) { - throw new InvalidArgumentException(sprintf('The object must implement the "%s".', TranslatableInterface::class)); + throw NotNormalizableValueException::createForUnexpectedDataType(sprintf('The object must implement the "%s".', TranslatableInterface::class), $object, [TranslatableInterface::class]); } return $object->trans($this->translator, $context[self::NORMALIZATION_LOCALE_KEY] ?? $this->defaultContext[self::NORMALIZATION_LOCALE_KEY]);