FOSJsRoutingBundle icon indicating copy to clipboard operation
FOSJsRoutingBundle copied to clipboard

Use default Symfony serializer service when available

Open magarzon opened this issue 8 years ago • 3 comments

Previous to this PR, the bundle created a new service using the same class as the Symfony Serializer, what, apart from redundant, makes problems with autowiring (two services with the same class).

With this PR, if the serializer service exists, it's used, tagging the custom normalizers.

If the serializer services doesn't exist, it's registered as before (more or less, instead from file, is registered using a Compiler Pass)

Tests are ok (updated one and adding another)

magarzon avatar Feb 24 '17 12:02 magarzon

This means that normalizers created for this bundle are now included in the serializer used by your app (which could cause issues depending on the kind of objects you use) and that your own normalizers are now called when serializing the data in the bundle (which can totally break the features of the bundle depending of what your normalizers are, as your own normalizer could be used instead). So I'm -1 on this.

If the issue is autowiring, the solution would be for Symfony to mark the main serializer services as the one used for autowiring, as it does already for the translator or the router for instance.

stof avatar Feb 24 '17 12:02 stof

@stof to have a normalizer that supports the normalization of RouteCollection or RoutesResponse it's weird, or you want to do the same this bundle do, so should be redundant. If you have a normalizer so generic that can be chosen instead of this bundle ones, you probably have a bigger problem (although you can play with priorities)

Anyway, probably adding a configuration parameter to select if you want the main serializer or the bundle one could be useful/valid?

magarzon avatar Feb 24 '17 12:02 magarzon

As the bundle now requires the symfony serializer (and PHP 8), I think this PR can be closed.

tacman avatar Nov 28 '23 16:11 tacman