0
votes

I'm using Symfony 6.0.7 and noticed this Behavior:

When I register a custom serializer as service, it gets added as encoder to the default "@serializer" one.

Why is this the case and how can I change this behavior?

My problem is, that this messes up the error handling of the FOSRestBundle which now always outputs the stacktrace of an exception even when debug is set to false.

My services.yaml

foo.serializer:
  class: Symfony\Component\Serializer\Serializer
  ...
  ...

This is what I get when dumping the encoders of the "@serializer" service:

...
array (size=5)
  0 => 
    object(Symfony\Component\Serializer\Serializer)[308]  <== @foo.serializer instance
      protected 'encoder' => 
        object(Symfony\Component\Serializer\Encoder\ChainEncoder)[332]
          private array 'encoders' => 
            array (size=1)
              ...
          private array 'encoderByFormat' => 
            array (size=0)
...
you might want to check the priority of your serializer since it might matter in which order they are loaded/used. another option might be to restrict your Serializer to entity types which you want to support during Serialization.LBA