Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Serializer] Improve ExtraAttributesException usefulness: provide attributes path #46283

Closed
@aprat84

Description

@aprat84

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