JMSSerializerBundle
JMSSerializerBundle copied to clipboard
can't inject service in subscriber
I am trying to create subscriber and use onPostSerialize method everything works fine until I needed to inject container in Subscriber's constructor
<service id="app.resources_config_serializer_subscriber.link_serialization_subscriber" class="AppBundle\Resources\config\serializer\Subscriber\LinkSerializationSubscriber" autowire="true" public="true">
<tag name="jms_serializer.event_subscriber" />
<argument type="service" id="service_container" />
</service>
I keep getting
Type error: Too few arguments to function AppBundle\\Resources\\config\\serializer\\Subscriber\\LinkSerializationSubscriber::__construct(), 0 passed in var/cache/dev/ContainerJhxxdml/getJmsSerializerService.php on line 27 and exactly 1 expected"
it seem like onPostSerialize is called twice because i could dump container but when i remove the dump statement, the error happens again.
public function __construct(Container $container)
{
$this->container = $container;
}
I think your issue is related to symfony auto wiring.... not to this bundle. Make sure autowring is well configured