{"action":"created","issue":{"url":"https://api.github.com/repos/symfony/symfony/issues/17642","labels_url":"https://api.github.com/repos/symfony/symfony/issues/17642/labels{/name}","comments_url":"https://api.github.com/repos/symfony/symfony/issues/17642/comments","events_url":"https://api.github.com/repos/symfony/symfony/issues/17642/events","html_url":"https://github.com/symfony/symfony/pull/17642","id":130429819,"number":17642,"title":"[FrameworkBundle] [DX] Add `Controller::json` method to make it easy to send json","user":{"login":"mcfedr","id":704356,"avatar_url":"https://avatars.githubusercontent.com/u/704356?v=3","gravatar_id":"","url":"https://api.github.com/users/mcfedr","html_url":"https://github.com/mcfedr","followers_url":"https://api.github.com/users/mcfedr/followers","following_url":"https://api.github.com/users/mcfedr/following{/other_user}","gists_url":"https://api.github.com/users/mcfedr/gists{/gist_id}","starred_url":"https://api.github.com/users/mcfedr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mcfedr/subscriptions","organizations_url":"https://api.github.com/users/mcfedr/orgs","repos_url":"https://api.github.com/users/mcfedr/repos","events_url":"https://api.github.com/users/mcfedr/events{/privacy}","received_events_url":"https://api.github.com/users/mcfedr/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/symfony/symfony/labels/Status:%20Needs%20Review","name":"Status: Needs Review","color":"ededed"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-02-01T17:38:23Z","updated_at":"2016-02-01T20:43:22Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/symfony/symfony/pulls/17642","html_url":"https://github.com/symfony/symfony/pull/17642","diff_url":"https://github.com/symfony/symfony/pull/17642.diff","patch_url":"https://github.com/symfony/symfony/pull/17642.patch"},"body":"Its currently a awkward to use Serializer component to send a `JsonResponse`.\r\n\r\nI have tried two approaches\r\n\r\n1. use `Serializer::normalize` and `JsonResponse`\r\n1. use `Serializer::serialize` and a plain `Response`, and set the `content-type`\r\n\r\nIn either cases there is need for a custom `json` function so as not to repeat yourself and there are disadvantages.\r\n\r\n1. In the first case you are only partly using `Serializer` and any custom `Encoder` would be skipped\r\n1. In the second you are not making use of `JsonResponse`, particular disadvantage if you want to support JSONP. \r\n\r\nThis new `json` method uses the serializer component is enabled it is used to generate the json data, and falls back to normal `JsonResponse` when its not.\r\n\r\n| Q             | A\r\n| ------------- | ---\r\n| Bug fix?      | no\r\n| New feature?  | yes\r\n| BC breaks?    | no\r\n| Deprecations? | no\r\n| Tests pass?   | yes\r\n| Fixed tickets | \r\n| License       | MIT\r\n| Doc PR        | "},"comment":{"url":"https://api.github.com/repos/symfony/symfony/issues/comments/178179543","html_url":"https://github.com/symfony/symfony/pull/17642#issuecomment-178179543","issue_url":"https://api.github.com/repos/symfony/symfony/issues/17642","id":178179543,"user":{"login":"mcfedr","id":704356,"avatar_url":"https://avatars.githubusercontent.com/u/704356?v=3","gravatar_id":"","url":"https://api.github.com/users/mcfedr","html_url":"https://github.com/mcfedr","followers_url":"https://api.github.com/users/mcfedr/followers","following_url":"https://api.github.com/users/mcfedr/following{/other_user}","gists_url":"https://api.github.com/users/mcfedr/gists{/gist_id}","starred_url":"https://api.github.com/users/mcfedr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mcfedr/subscriptions","organizations_url":"https://api.github.com/users/mcfedr/orgs","repos_url":"https://api.github.com/users/mcfedr/repos","events_url":"https://api.github.com/users/mcfedr/events{/privacy}","received_events_url":"https://api.github.com/users/mcfedr/received_events","type":"User","site_admin":false},"created_at":"2016-02-01T20:43:22Z","updated_at":"2016-02-01T20:43:22Z","body":"Now I look at it again, I completely agree on the weirdness of inserting the Serializer into the Response.\r\n\r\nHow about what I have done now? Its very similar to how DunglasApiBundle does it, but keeping the `JsonResponse`."}}