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 4 - Class 'jms_serializer.stopwatch_subscriber' not found #610

Closed
kgasienica opened this issue Oct 26, 2017 · 15 comments
Closed

Symfony 4 - Class 'jms_serializer.stopwatch_subscriber' not found #610

kgasienica opened this issue Oct 26, 2017 · 15 comments

Comments

@kgasienica
Copy link

In Symfony 4 I have occured a problem with JMSSerializerBundle in use with FOSRestBundle. My code looks like below:

$restresult = $this->getDoctrine()->getRepository('App:Entity')->findAll();
return View::create(['data' => $restresult], Response::HTTP_FOUND);

There is no problem when data is a pure array, but when there are even simple objects (f.ex. DateTime) that problem occurs.

Deleting JMSSerializerBundle from Kernel.php fixes the problem, because Symfony takes his native serializer when JMSSerializerBundle is not found.

Error:

"error": {
"code": 500,
"message": "Internal Server Error",
"exception": [
{
"message": "Warning: call_user_func() expects parameter 1 to be a valid callback, class 'jms_serializer.stopwatch_subscriber' not found",
"class": "ErrorException",
"trace": [
{
"namespace": "",
"short_class": "",
"class": "",
"type": "",
"function": "",
"file": "/var/www/someproject/vendor/jms/serializer/src/JMS/Serializer/EventDispatcher/EventDispatcher.php",
"line": 104,
"args": []
},
{
"namespace": "JMS\\Serializer\\EventDispatcher",
"short_class": "EventDispatcher",
"class": "JMS\\Serializer\\EventDispatcher\\EventDispatcher",
"type": "->",
"function": "dispatch",
"file": "/var/www/someproject/vendor/jms/serializer/src/JMS/Serializer/GraphNavigator.php",
"line": 188,
"args": [
[
"string",
"serializer.pre_serialize"
],
[
"string",
"App\\Entity\\SomeEntity"
],
[
"string",
"json"
],
[
"object",
"JMS\\Serializer\\EventDispatcher\\PreSerializeEvent"
]
]
},
@goetas
Copy link
Collaborator

goetas commented Oct 26, 2017

#605 is still open (and symfony 4 is not yer released), means that this bundle is not yet fully compatible with symfony 4

@surikman
Copy link

surikman commented Nov 2, 2017

Hi, this is not a symfony bug, you have to change configuration of services which you can retrieve directly from the container - according to symfony/dependency-injection@a043965#diff-09eda9d53bdc62a97ad02badf08be429

“ deprecated "public-by-default" definitions and aliases, the new default will be "private" in 4.0 "

All services in symfony 4 are private, except explicit setup "public" flag on it

@surikman
Copy link

surikman commented Nov 2, 2017

I found out, that this services have to be public (because LazyEventDispatcher)

<service id="jms_serializer.doctrine_proxy_subscriber" class="%jms_serializer.doctrine_proxy_subscriber.class%" public="true">
<service id="jms_serializer.stopwatch_subscriber" class="%jms_serializer.stopwatch_subscriber.class%" public="true">

and

<service id="jms_serializer.metadata_driver" alias="jms_serializer.metadata.chain_driver" public="true" />

because LazyLoadingDriver

Or you may change it and use lazy=true flag on service definition and remove Lazy* Services...

@goetas
Copy link
Collaborator

goetas commented Nov 2, 2017

this will be "solved" by the bundle right after the symfony release

@Rastusik
Copy link

Rastusik commented Nov 2, 2017

@goetas would it at least be possible to create a separate feature branch with this issue fixed? It would allow our team to move faster until S4 is released

@goetas
Copy link
Collaborator

goetas commented Nov 2, 2017

@Rastusik sf4-compat branch tries to do that

@goetas
Copy link
Collaborator

goetas commented Nov 2, 2017

@kgasienica which bundle version are you using?

@Rastusik
Copy link

Rastusik commented Nov 2, 2017

@goetas great, thank you very much!

@kgasienica
Copy link
Author

@goetas it was

"jms/serializer-bundle": "^2.0@dev",

@goetas
Copy link
Collaborator

goetas commented Nov 2, 2017

@kgasienica there is a chance that your specific problem was solved with v2.2.0

@kgasienica
Copy link
Author

After add those services in config.yml, there is still a problem with one service:
jms_serializer.metadata_driver
This one even if I put to run as public is not starting and is not on the services list.

@cryptiklemur
Copy link

cryptiklemur commented Nov 7, 2017

Appears to still be broken in v2.2.0 @goetas, same with sf4-compat

@luishdez
Copy link

luishdez commented Nov 15, 2017

@kgasienica What error are you getting ? I just override the services in my services.yml and it's working fine.

services:
    jms_serializer.doctrine_proxy_subscriber:
        class: JMS\Serializer\EventDispatcher\Subscriber\DoctrineProxySubscriber
        public: true
        tags:
            - { name: jms_serializer.event_subscriber }
        arguments:
            - true
            - false
    jms_serializer.stopwatch_subscriber:
        class: JMS\SerializerBundle\Serializer\StopwatchEventSubscriber
        public: true
        arguments:
            - "?debug.stopwatch"
    jms_serializer.datetime_handler:
        class: JMS\Serializer\Handler\DateHandler
        public: true
        tags:
            - { name: jms_serializer.subscribing_handler }
    jms_serializer.array_collection_handler:
        class: JMS\Serializer\Handler\ArrayCollectionHandler
        public: true
        tags:
            - { name: jms_serializer.subscribing_handler }

# You may need to make public other handlers

BTW services are private as default since 3.4 https://symfony.com/blog/new-in-symfony-3-4-services-are-private-by-default

@surikman
Copy link

@luishdez yes, if you override this services, it works fine, but we expect it without overrideing.

jms_serializer.metadata_driver was changed in sf4-compat branche, but, not doctrine_proxy_subscriber and stopwatch_subscriber

This two are still required to be public.

I create a pull request for it. #614

@goetas
Copy link
Collaborator

goetas commented Nov 22, 2017

will be solved in #605

@goetas goetas closed this as completed Nov 22, 2017
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