Skip to content

Navigation Menu

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] Improve ExtraAttributesException usefulness: provide attributes path #46283

Copy link
Copy link
Closed
@aprat84

Description

@aprat84
Issue body actions

Description

This exception does not provide property path for the extra attributes found. So if they are in nested object, We are not able to construct reliable validation errors for our users, rather than a generic "Invalid input data: extra attributes found".

Example

class CategoryDto {
    public string $name;
}

class ProductDto {
    public string $name;
    public Category $category1;
    public Category $category2;
}
{
  "name": "Product name",
  "category1": {
    "name": "Category name",
    "extra": "some extra field"
  },
  "category2": {
    "name": "Category name"
  }
}

If I deserialize this JSON into ProductDto, it results in a ExtraAttributesException, which is correct.
But, the ExtraAttributesException::getExtraAttributes() returns the following:

array(1) {
  [0]=>
  string(5) "extra"
}

Which doesn't provide info about the exact property (path included) that is not allowed.

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.