You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
JSON:API: relations set through the constructor reject spec resource linkage (relationships.<name>.data) #8702
When a relation is set through a constructor argument, the JSON:API denormalizer does not accept the resource linkage shape of the spec (relationships.<name>.data).
To-one with {"data": {"type": ..., "id": ...}} or {"data": null}: 400 "Only resource linkage supported currently".
To-many with {"data": [...]}: 400 "The type of the key "data" must be "int", "string" given."
To-one with the flat shape {"type": ..., "id": ...}, which is not the spec shape: 201.
The same relation as a public property (no constructor) accepts the spec shape.
The cause looks like this: JsonApi\Serializer\ItemNormalizerTrait::setAttributeValue() removes the data wrapper, but AbstractItemNormalizer::createConstructorArgument() calls createAndValidateAttributeValue() directly. The JSON:API normalizer does not override it, so the value still has the data wrapper when it gets to denormalizeRelation().
Expected: a relation set through the constructor accepts the same relationships.<name>.data shape as a relation set through a property. The flat shape is not accepted.
Possible Solution
Remove the data wrapper for constructor arguments too, for example with a createConstructorArgument() override in ItemNormalizerTrait that does what setAttributeValue() does.
Additional Context
Checked on api-platform/core v4.4.4, Symfony 7.4, PHP 8.5, in an empty Symfony app. The related code in src/JsonApi/Serializer is the same on main, except for the error status cast (#8366).
The app has only FrameworkBundle, TwigBundle and ApiPlatformBundle, with this config:
All requests send Accept: application/vnd.api+json and, when they have a body, Content-Type: application/vnd.api+json. The responses are from the prod environment.
Activity
fix(jsonapi): unwrap relationship linkage before denormalization
fix(jsonapi): unwrap relationship linkage before denormalization (#8730)