. */ namespace App\Serializer; use Brick\Math\BigDecimal; use Brick\Math\BigNumber; use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface; class BigNumberSerializer implements ContextAwareNormalizerInterface { public function supportsNormalization($data, string $format = null, array $context = []) { return $data instanceof BigNumber; } public function normalize($object, string $format = null, array $context = []) { if (!$object instanceof BigNumber) { throw new \InvalidArgumentException('This normalizer only supports BigNumber objects!'); } return (string) $object; } }