Search code examples
phpsymfonyconstructordeprecation-warning

How can I fix a deprecated user in Symfony 4?


I get the following error message:

User Deprecated: Passing configuration options directly to the constructor is deprecated since Symfony 4.2, use the default context instead.

This is the code Symfony is giving as trace for the problem:

$serializer = new Serializer(array(new DateTimeNormalizer('d.m.Y'), new GetSetMethodNormalizer()), array('json' => new JsonEncoder()));

But I do not understand how to use a default context


Solution

  • You have to use directly the service.

    class DefaultController extends AbstractController
    {
        public function index(SerializerInterface $serializer)
        {
            // keep reading for usage examples
        }
    }
    

    https://symfony.com/doc/current/serializer.html