Skip to content

[Serializer] Wrong path in NotNormalizableValueException #45470

@mar3

Description

@mar3

Symfony version(s) affected

6.0.2

Description

There is wrong path in NotNormalizableValueException:

$normalizers = [
    new ArrayDenormalizer(),
    new ObjectNormalizer(null, null, null,
        new PropertyInfoExtractor(
            [new ReflectionExtractor()],
            [new PhpDocExtractor(), new ReflectionExtractor()],
        )
    ),
];
$serializer = new Serializer($normalizers, [new JsonEncoder()]);
try {
    $car = $serializer->deserialize('{
      "id": 1,
      "parts": [{
        "id": "int type"
      }],
      "owner": {
        "id": "int type"
      }
    }', Car::class, 'json', [DenormalizerInterface::COLLECT_DENORMALIZATION_ERRORS => true]);
} catch (PartialDenormalizationException $e) {
    dd($e->getErrors());
}

Dumped errors:

0 => Symfony\Component\Serializer\Exception\NotNormalizableValueException {#3915 ▼
    #message: "The type of the "id" attribute for class "App\Part" must be one of "int" ("string" given)."
    -path: "[0]" // should be "parts[0].id"
    //...
}
1 => Symfony\Component\Serializer\Exception\NotNormalizableValueException {#2011 ▼
    #message: "The type of the "id" attribute for class "App\Owner" must be one of "int" ("string" given)."
    -path: "id" // should be "owner.id"
    //...
}

How to reproduce

https://github.com/mar3/symfony-serializer-path-bug
src/Controller/TestController.php

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