Quantcast
Channel: Active questions tagged symfony4 - Stack Overflow
Viewing all articles
Browse latest Browse all 3924

symfony 4.2 max_depth_handler serializer how to implement?

$
0
0

Just an hour ago I asked a question about the new circular_reference_handler in symfony 4.2's serializer.

(Use the "circular_reference_handler" key of the context instead symfony 4.2)

The answer to that question leads me to a new problem of the maximum nesting level reached.

In the documentation (https://symfony.com/doc/current/components/serializer.html#handling-serialization-depth)

There is no mention of this context key or how to implement it.

If I use the example of the circular_reference_handler of my previous question i'll add the context key in the framework.yaml file under :

framework:    serializer:        max_depth_handler: 'App\Serializer\MyMaxDepthHandler'

And create the class

namespace App\Serializer;class MyMaxDepthHandler    {    public function __invoke($object){        //TODO how to handle this    }}

And in order for the serializer to use this handler I set the context for the serialize function :

$this->serializer->serialize($object, 'json', ['enable_max_depth' => true]);

Now my question is how do I handle this ? Does anyone have an example of what to put in the body of this __invoke function ?

Any help would be greatly appreciated


Viewing all articles
Browse latest Browse all 3924

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>