JMSSerializerBundle icon indicating copy to clipboard operation
JMSSerializerBundle copied to clipboard

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

Open phtmgt opened this issue 6 years ago • 5 comments

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

phtmgt avatar Jun 05 '19 07:06 phtmgt

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

goetas avatar Jun 05 '19 07:06 goetas

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

pavelkameisha avatar Oct 11 '19 11:10 pavelkameisha

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 .

goetas avatar Oct 11 '19 11:10 goetas

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

DimaSerikov avatar Jan 30 '20 14:01 DimaSerikov

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?

llupa avatar Sep 17 '21 12:09 llupa