Thank you for this awesome library. I am running into a weird problem when I call $this->json($data) in symfony 3.1 controller. This is the error I am getting is
Type error: Argument 3 passed to JMS\Serializer\Serializer::serialize() must be an instance of JMS\Serializer\SerializationContext, array given, called in /app/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php on line 117
jms/serializer-bundle version 1.1
jms/serializer version 1.2
Thank you
@askhalil to fix this you need to disable short alias ("serializer") for JMS Serializer:
# app/config/config.yml
jms_serializer:
enable_short_alias: false
@askhalil could close this issue ? The @kubawerlos's tip resolves this problem.
@yceruto I dont think so. If you disable short alias, then \Symfony\Bundle\FrameworkBundle\Controller\Controller::json will not use JMSSerializerBundle, but json_encode or symfony serializer component if enabled. This should be fixed.
If you disable short alias, then \Symfony\Bundle\FrameworkBundle\Controller\Controller::json will not use JMSSerializerBundle.
It is still the expected behavior. Symfony does not use JMSSerializerBundle by default, but json_encode or Symfony Serializer Component if enabled (as you said).
This should be fixed.
If you need serialize all json response with JMSSerializeBundle, you need then override the Controller::json() controller/method in your app. JMSSerializeBundle cannot solve this, simply disable the short alias to avoid conflicts.
@yceruto Then it should be visible writen in documentation, because it is unexpected behaviour. Everyone will see it as bug.
as posted by @yceruto here
the solution is:
# app/config/config.yml
jms_serializer:
enable_short_alias: false
@Tetragramat PR to the documentation are welcome
@goetas
Hi , the option enable_short_alias has been abandoned?
yes, for the 2.x versions, the alias is always jms_serializer
(just serializer has been reserved for the symfony serializer)
Most helpful comment
@askhalil to fix this you need to disable short alias ("serializer") for JMS Serializer: