Skip to content

Exception on POST JSON object with numeric property #5464

@alebedev80

Description

@alebedev80

API Platform version(s) affected: 3.1.4, 2.7.9
PHP version: 8.2.3
Description
On POST request to endpoint with JSON object where one property is numeric will be exception

"hydra:description": "ApiPlatform\\Serializer\\AbstractItemNormalizer::canAccessAttributePostDenormalize(): Argument #3 ($attribute) must be of type string, int given, called in /srv/app/vendor/api-platform/core/src/Serializer/AbstractItemNormalizer.php on line 227"

How to reproduce

  1. Set-up API Platform
  2. Send request
curl -vk --location 'https://localhost/greetings' \
--header 'Content-Type: application/json' \
--data '{
    "0": 1
}'

or

curl 'https://demo.api-platform.com/books' -v -H 'content-type: application/ld+json' --data-raw '{"0":"1"}'

Possible Solution
As quick fix i locally inserted a row \ApiPlatform\Serializer\AbstractItemNormalizer:227

$attribute = (string)$attribute;

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions