Skip to content

SerializerDataCollector bugs #46589

Closed
Closed
@b1rdex

Description

@b1rdex

Symfony version(s) affected

6.1

Description

1️⃣ The first thing:
Create a simple controller with an exception:

#[Route('/test')]
public function test(SerializerInterface $serializer)
{
    $json = $serializer->serialize([], 'json');
    throw new \Exception();
}

Open it with a browser, then navigate to Profiler, then to panel Serializer and an error is rendered:
image

Twig\Error\RuntimeError:
Key "normalizer" for array with keys "data, dataType, type, format, time, context, normalization, encoding, encoder" does not exist.

  at /redacted/vendor/symfony/web-profiler-bundle/Resources/views/Collector/serializer.html.twig:191

2️⃣ The second thing:
Create a simple controller and a class:

#[Route('/test2')]
public function test2(SerializerInterface $serializer)
{
    $serializer->deserialize(
        json_encode(['test' => 'string'], JSON_THROW_ON_ERROR),
        Foo::class,
        'json',
    );
}
}

class Foo {
    public array $test = [];
}

Open /test2 with a browser and notice that profiler panel is Loading... (because profiler data wasn't saved):
image

I'm not sure how to get a correct trace for the second case, but there are some problems in the collector:

Undefined array key "data" at vendor/symfony/serializer/DataCollector/SerializerDataCollector.php:183 
Undefined array key "format" at vendor/symfony/serializer/DataCollector/SerializerDataCollector.php:186
Undefined array key "time" at vendor/symfony/serializer/DataCollector/SerializerDataCollector.php:188
Undefined array key "context" at vendor/symfony/serializer/DataCollector/SerializerDataCollector.php:189
Undefined array key "method" at vendor/symfony/serializer/DataCollector/SerializerDataCollector.php:224

How to reproduce

Please see the description

Possible Solution

No response

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions