json_encode recursion detected warning

Fixes symfony/symfony#6427