Skip to content

[Serializer][PropertyInfo] PHPDocExtractor is failing with array<string, mixed> #47224

Closed
@Hanmac

Description

@Hanmac

Symfony version(s) affected

4.4.x

Description

I was first using a Mockup UnitTest using ReflectionExtractor with ObjectNormalizer which did work

then i was trying to use a functional Test where i wanted to have the Services, but the Denormalize is failing:

The type of the "settings" attribute for class "Sonata\PageBundle\Tests\App\Entity\SonataPageBlock" must be one of "rray<string,mixed>"

This is the property:

    /**
     * @var array<string, mixed>
     */
    protected $settings;

notice the missing a from array?

i assume that this version of PropertyInfo the PHPDoc Extractor has problems with such array type, or is the definition wrong?

How to reproduce

Class Block
{

    /**
     * @var array<string, mixed>
     */
    protected $settings;


    public function setSettings(array $settings = []): void
    {
        $this->settings = $settings;
    }

    public function getSettings(): array
    {
        return $this->settings;
    }
}

Did a Breakpoint in the constructor of PropertyInfoExtractor
The $typeExtractors is called with a generator with 2 closures, the first is the doctrine Extractor, the second is the phpdoc extractor, the third one is missing, the count of the generator is 3

and the PHPDoc Extractor does something stupid with the type

Possible Solution

No response

Additional Context

Error when trying to denormalize

Symfony\Component\Serializer\Exception\NotNormalizableValueException : The type of the "settings" attribute for class "Sonata\PageBundle\Tests\App\Entity\SonataPageBlock" must be one of "rray<string,mixed>" ("array" given).
 /opt/project/vendor/symfony/serializer/Normalizer/AbstractObjectNormalizer.php:477
 /opt/project/vendor/symfony/serializer/Normalizer/AbstractObjectNormalizer.php:358
 /opt/project/vendor/symfony/serializer/Serializer.php:191

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