Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symfony 3 'json' method gives errors with JMS #523

Closed
askhalil opened this issue Aug 11, 2016 · 9 comments
Closed

Symfony 3 'json' method gives errors with JMS #523

askhalil opened this issue Aug 11, 2016 · 9 comments

Comments

@askhalil
Copy link

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

@kubawerlos
Copy link

@askhalil to fix this you need to disable short alias ("serializer") for JMS Serializer:

# app/config/config.yml

jms_serializer:
    enable_short_alias: false

@yceruto
Copy link

yceruto commented Nov 23, 2016

@askhalil could close this issue ? The @kubawerlos's tip resolves this problem.

@Tetragramat
Copy link

@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.

@yceruto
Copy link

yceruto commented Jan 2, 2017

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.

@Tetragramat
Copy link

@yceruto Then it should be visible writen in documentation, because it is unexpected behaviour. Everyone will see it as bug.

@goetas
Copy link
Collaborator

goetas commented Jan 3, 2017

as posted by @yceruto here

the solution is:

# app/config/config.yml

jms_serializer:
    enable_short_alias: false

@goetas goetas closed this as completed Jan 3, 2017
@goetas
Copy link
Collaborator

goetas commented Jan 3, 2017

@Tetragramat PR to the documentation are welcome

@slince
Copy link

slince commented Nov 2, 2017

@goetas
Hi , the option enable_short_alias has been abandoned?

@goetas
Copy link
Collaborator

goetas commented Nov 2, 2017

yes, for the 2.x versions, the alias is always jms_serializer

(just serializer has been reserved for the symfony serializer)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants