-
-
Notifications
You must be signed in to change notification settings - Fork 889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HAL serializer doesn't respect skip_null_values=false for relations #4372
Comments
The fix you propose looks good to me. Would you like to work on a patch? |
I have created a PR #4373 for demonstration, but I have run into problems. The hyperschema does not allow
So, to proceed, I see multiple options.
{
"_links": {
"self": { "href": "/some/iri" }
}
}
{
"_links": {
"self": { "href": "/some/iri" },
"relatedDummy": null
},
"_embedded": {
"relatedDummy": null
}
}
{
"_links": {
"self": { "href": "/some/iri" },
"relatedDummy": { "href": null }
},
"_embedded": {
"relatedDummy": null
}
}
{
"_links": {
"self": { "href": "/some/iri" }
},
"relatedDummy": null
} To summarize:
What do you think? Which way would you choose? |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
API Platform version(s) affected: 2.6.5, and any other API platform version using Symfony 4.2 (since the introduction of the
skip_null_values
flag)Description
The HAL format normalizer does things a little differently from the rest of the normalizers, especially when it comes to normalizing relations. In ItemNormalizer#populateRelation, an
empty()
check determines whether to leave out a relation. This also affects optional ToOne relations which can have a null value. In the rest of the framework, theskip_null_values
flag in the context determines what to do with such null relations. In HAL, this flag is not respected.I'd be glad to provide a PR to fix this if requested.
How to reproduce
Create two entities like the following:
Activate support for HAL in the config:
Create a
Dummy
instance in the database without anyRelatedDummy
, and fetch it using the formatAccept: application/hal+json
.Expected result:
Actual result:
Possible Solution
Use a check like the following:
The text was updated successfully, but these errors were encountered: