-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
JsonResponse makes it impossible to send literal null #11679
Comments
This seems to be the desired value since there actually is a test ensuring this behaviour: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpFoundation/Tests/JsonResponseTest.php#L18-22 You can use the $response = new JsonResponse();
$response->setData(null); |
Thanks, that works as a workaround. |
the goal is that calling Note that this cannot be changed for BC (I don't know many APIs returning |
Can we please document this behaviour somewhere? It's bizarre behaviour to me, and suggests a misunderstanding of the JSON specification from whoever originally implemented it, but at least if it was written down somewhere in the PHPdoc I wouldn't have wasted time wondering what was going on |
Go ahead and propose the piece of documentation that would've helped you to https://github.com/symfony/symfony-docs/ |
What's about adding also a testcase for this behavior and using setData ? |
… content (xabbuh) This PR was merged into the 5.4 branch. Discussion ---------- [HttpFoundation] add test for JSON response with null as content | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | #11679 (comment) | License | MIT Commits ------- 5c37277 add test for JSON response with null as content
…768) This PR was merged into the 5.4 branch. Discussion ---------- Document strange JsonResponse constructor behaviour Discussed on symfony/symfony#11679 Commits ------- 90fa8ca Respond to "patches welcome" comment
The default value of the
$data
parameter forJsonResponse
is null, but when it is set to null, the actual value sent in the response is in fact{}
. This is problematic because it makes it impossible to send a literal value ofnull
, which is valid JSON. The distinction is important, because in javascript{}
evaluates truthy andnull
evaluates falsy.The text was updated successfully, but these errors were encountered: