Open alebedev80 opened 1 year ago
Book has no 0
property
@soyuka yes! A book has no property 0, but code raise exception and server response 500 because invalid argument type in method call at ApiPlatform\Serializer\AbstractItemNormalizer:227. You can't expect that users will send proper data. So please re-open this issue. That's a bug!
curl 'https://demo.api-platform.com/books' -v -H 'content-type: application/ld+json' --data-raw '{"0":"1"}'
...
< status: 500 Internal Server Error
...
{"@context":"\/contexts\/Error","@type":"hydra:Error","hydra:title":"An error occurred","hydra:description":"Internal Server Error"}
I don't understand, what exception do you expect?
@soyuka i don't expect any exception in that case ;)
I think that this should throw a 400 Bad Request
. Tagging as bug.
@soyuka i'm not sure that this should throw 400 because on post a json string property which is 'unexpected' per service that property just ignoring. I think behavior should be the same - just ignore that numeric property.
@soyuka imho if by this request response is 201:
curl 'https://demo.api-platform.com/books' -v -H 'content-type: application/ld+json' --data-raw '{"author":"a", "title": "t", "description": "d", "publicationDate": "2023-03-16", "x": "0"}'
then by request with numeric property also should be 201:
curl 'https://demo.api-platform.com/books' -v -H 'content-type: application/ld+json' --data-raw '{"author":"a", "title": "t", "description": "d", "publicationDate": "2023-03-16", "0": "0"}'
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
How to reproduce
or
Possible Solution
As quick fix i locally inserted a row \ApiPlatform\Serializer\AbstractItemNormalizer:227