. */ namespace App\Serializer; use Brick\Math\BigNumber; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; /** * @see \App\Tests\Serializer\BigNumberNormalizerTest */ class BigNumberNormalizer implements NormalizerInterface { public function supportsNormalization($data, string $format = null, array $context = []): bool { return $data instanceof BigNumber; } public function normalize($object, string $format = null, array $context = []): string { if (!$object instanceof BigNumber) { throw new \InvalidArgumentException('This normalizer only supports BigNumber objects!'); } return (string) $object; } /** * @return bool[] */ public function getSupportedTypes(?string $format): array { return [ BigNumber::class => true, ]; } }