Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Serializer] Wrong path in NotNormalizableValueException #45470

Copy link
Copy link
Closed
@mar3

Description

@mar3
Issue body actions

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.