JMSSerializerBundle: Symfony 4 - Class 'jms_serializer.stopwatch_subscriber' not found

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"
]
]
},

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 15

Most upvoted comments

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

@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. https://github.com/schmittjoh/JMSSerializerBundle/pull/614

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…