Attempted to call an undefined method named "setDepth" of class "JMS\Serializer\Visitor\Factory\JsonSerializationVisitorFactory".
Just upgraded from 2.x to 3.x and this is the error I get. It seems to be related to:
visitors:
json_serialization:
options: 0 # json_encode options bitmask, suggested JSON_PRETTY_PRINT in development
depth: 512
However, when I remove the depth option, I get:
Context visitingStack not working well
I think your is a valid bug, the method setDepth is missing in https://github.com/schmittjoh/serializer/blob/master/src/Visitor/Factory/JsonSerializationVisitorFactory.php
I have the same trouble. When I try to serialize entity which has related data, application throws exception Context visitingStack not working well.
This is most likely related to some type mapping error, like some entities have a type "array" but in reality they are doctrine collections.
Days ago this https://github.com/schmittjoh/JMSSerializerBundle/issues/596 was solved. Can it be related? Which version are you using?
On Fri, 11 Oct 2019, 13:15 SunPaulo, [email protected] wrote:
I have the same trouble. When I try to serialize entity which has related data, application throws exception Context visitingStack not working well.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/schmittjoh/JMSSerializerBundle/issues/751?email_source=notifications&email_token=AAF5UJ46XIDNSPME77R6LL3QOBN4PA5CNFSM4HTRJW42YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEA7VRHA#issuecomment-541022364, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAF5UJYRFI2PBHHK3VDZMXLQOBN4PANCNFSM4HTRJW4Q .
The same error Context visitingStack not working well, when try to serialize entity which has related model (@JMS\Type("App\MyClass\MyModel")).
When I commented those stings in JMS\Serializer\SerializationContext:
//if ($object !== $poppedObject) { // throw new RuntimeException('Context visitingStack not working well'); // }
debug shows a real type hinting error Return value of ... must be an instance of ..., null returned
I had the same as the original post. Upgrade from v2 to v3 and I was greeted with: Call to undefined method JMS\Serializer\Visitor\Factory\JsonSerializationVisitorFactory::setDepth()
Did some digging and this is what I gathered:
version: 3.10.0
Configuration.php
$builder
->arrayNode('visitors')
->addDefaultsIfNotSet()
->children()
->arrayNode('json_serialization')
->addDefaultsIfNotSet()
->children()
->scalarNode('depth')->end()
It is a configurable option.
JMSSerializerExtension.php
if (isset($config['visitors']['json_serialization']['depth'])) {
$container->getDefinition('jms_serializer.json_serialization_visitor')
->addMethodCall('setDepth', [$config['visitors']['json_serialization']['depth']]);
}
If set, as shown in the docs or upgrade guide a method call is added for jms_serializer.json_serialization_visitor a.k.a JMS\Serializer\Visitor\Factory\JsonSerializationVisitorFactory and yes, this class does not have this method as @goetas already mentioned above. This has been the case for 2 years it seems.
Is this a case of wrong documentation or the factory is wrong?