Skip to content

Commit ef45660

Browse files
committed
throw better exception in TranslatableNormalizer, add to changelog
1 parent b066c78 commit ef45660

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGELOG
44
6.4
55
---
66

7+
* Add `TranslatableNormalizer`
78
* Allow `Context` attribute to target classes
89
* Deprecate Doctrine annotations support in favor of native attributes
910
* Allow the `Groups` attribute/annotation on classes

Normalizer/TranslatableNormalizer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Serializer\Normalizer;
1313

1414
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
15+
use Symfony\Component\Serializer\Exception\NotNormalizableValueException;
1516
use Symfony\Contracts\Translation\TranslatableInterface;
1617
use Symfony\Contracts\Translation\TranslatorInterface;
1718

@@ -36,7 +37,7 @@ public function __construct(
3637
public function normalize(mixed $object, string $format = null, array $context = []): string
3738
{
3839
if (!$object instanceof TranslatableInterface) {
39-
throw new InvalidArgumentException(sprintf('The object must implement the "%s".', TranslatableInterface::class));
40+
throw NotNormalizableValueException::createForUnexpectedDataType(sprintf('The object must implement the "%s".', TranslatableInterface::class), $object, [TranslatableInterface::class]);
4041
}
4142

4243
return $object->trans($this->translator, $context[self::NORMALIZATION_LOCALE_KEY] ?? $this->defaultContext[self::NORMALIZATION_LOCALE_KEY]);

0 commit comments

Comments
 (0)