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

Attempted to call an undefined method named "setDepth" of class "JMS\Serializer\Visitor\Factory\JsonSerializationVisitorFactory". #751

Open
phtmgt opened this issue Jun 5, 2019 · 5 comments

Comments

@phtmgt
Copy link

phtmgt commented Jun 5, 2019

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

@goetas
Copy link
Collaborator

goetas commented Jun 5, 2019

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

@sunpaulo
Copy link

I have the same trouble. When I try to serialize entity which has related data, application throws exception Context visitingStack not working well.

@goetas
Copy link
Collaborator

goetas commented Oct 11, 2019 via email

@DimaSerikov
Copy link

DimaSerikov commented Jan 30, 2020

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

@llupa
Copy link

llupa commented Sep 17, 2021

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?

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

No branches or pull requests

5 participants