Cannot normalize attribute because the injected serializer is not a normalizer.

When using API Platform or symfony serializations, you can get this error

This error happens when you use an ObjectNormalizer Symfony\Component\Serializer\Normalizer\ObjectNormalizer

instead of an Symfony\Component\Serializer\Normalizer\NormalizerInterface

To avoit this error Use

Symfony\Component\Serializer\Normalizer\NormalizerInterface;