Skip to content

Denormalization of a two-dimensional array of objects broken #31175

Closed
@igneus

Description

@igneus

Symfony version(s) affected: 4.1, 4.2

Description
After upgrading an application from Symfony 4.1 to 4.2, deserialization of documents containing two-dimensional arrays of objects stopped working: objects in two-dimensional arrays never more get denormalized, associative arrays are produced instead.

I was able to narrow down the source of the problem to symfony/property-info - from version 4.1.4 on, type information from the annotation @var SomeClass[][] is represented differently, which brings about deadly consequences in AbstractObjectNormalizer::validateAndDenormalize: the type is treated as an array of arrays (=> no denormalization happens), while the type information produced by symfony/property-info up to 4.1.3 is treated as array of SomeClass[] (=> will be denormalized using ArrayDenormalizer and ObjectNormalizer).

How to reproduce
Setup:

  • deserializing a JSON containing a two-dimensional array of objects like {"content":[[{"name": "John"},{"name": "Jane"}], [{"name": "Peggy"}]]}
  • custom-built Serializer with ArrayDenormalizer and ObjectNormalizer
  • type information for nested objects is in phpDoc annotations, extracted using PhpDocExtractor
  • the property which after denormalization should contain a two-dimensional array of objects is annotated @var SomeClass[][]

I have created a minimal project reproducing the issue
https://github.com/igneus/symfony-deserialize-twodimensional-mwe
in a single test case
https://github.com/igneus/symfony-deserialize-twodimensional-mwe/blob/master/tests/TwoDimensionalDeserializeTest.php

master passes (symfony/property-info 4.1.2),
the other branches demonstrate the reported behaviour:

  • with4.1.4 - symfony/property-info 4.1.4, the first version affected
  • with4.2 - symfony/property-info 4.2.7 - current, still affected

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