core: JSON POST not working since version 2.4.7
Since version 2.4.7 the fallowing POST request with application/json is not working anymore:
{
"title": "Test document",
"articles": [
{
"title": "New Article",
"originalArticle": {"id": 21}
}
]
}
Throws an error:
No route matches “21”.
Version 2.4.6 is working.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 16 (11 by maintainers)
Even if it is new, this shouldn’t be done in a patch release. Definitely a BC break.
My investigation has revealed that it’s not a bug. In fact, it’s because we’ve fixed a bug which in turn revealed the problem with incorrect property metadata set on your API resources.
See #3145
Looks like I was the one who broke it: https://github.com/api-platform/core/blame/c1b89a13772f6ba9eb39fddbf83e3fad9faf3c00/src/Serializer/ItemNormalizer.php#L80
So I’m going to look into this. 😆
To expand on the earlier examples, this is the resource config and groups relation in my User entity. To the best of my knowledge this is exactly what you described? A serializer group in the denormalization context, right?
@nicklasaloq
It was never supposed to work that way, as far as I could tell. It just happened to be working, but that’s never been a supported use case (you can look at our test suite).
I have tried this:
It works in 2.4.6 and 2.4.7 as soon as
allow_plain_identifiersis turned on, as @teohhanhui pointed out, and yourContent-Typeheader isapplication/json(notapplication/ld+json).Beware that the example you provided is not correct: the server doesn’t expect
"book": {"id": 1}but"book": 1.@nicklasaloq Referencing the object by its IRI, e.g.
"book": "/api/books/1"is the recommended way indeed.