{"action":"created","comment":{"url":"https://api.github.com/repos/symfony/symfony/pulls/comments/51479017","id":51479017,"diff_hunk":"@@ -98,6 +100,28 @@ protected function redirectToRoute($route, array $parameters = array(), $status\n     }\n \n     /**\n+     * Returns a JsonResponse that uses the serializer component if enabled, or json_encode.\n+     *\n+     * @param mixed $data    The response data\n+     * @param int   $status  The status code to use for the Response\n+     * @param array $headers Array of extra headers to add\n+     * @param array $context Context to pass to serializer when using serializer component\n+     *\n+     * @return JsonResponse\n+     */\n+    protected function json($data, $status = 200, $headers = array(), $context = array())\n+    {\n+        if ($this->container->has('serializer')) {","path":"src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php","position":26,"original_position":26,"commit_id":"11bc1519d5977599b67ab352bfbf819b69c63f36","original_commit_id":"11bc1519d5977599b67ab352bfbf819b69c63f36","user":{"login":"dunglas","id":57224,"avatar_url":"https://avatars.githubusercontent.com/u/57224?v=3","gravatar_id":"","url":"https://api.github.com/users/dunglas","html_url":"https://github.com/dunglas","followers_url":"https://api.github.com/users/dunglas/followers","following_url":"https://api.github.com/users/dunglas/following{/other_user}","gists_url":"https://api.github.com/users/dunglas/gists{/gist_id}","starred_url":"https://api.github.com/users/dunglas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dunglas/subscriptions","organizations_url":"https://api.github.com/users/dunglas/orgs","repos_url":"https://api.github.com/users/dunglas/repos","events_url":"https://api.github.com/users/dunglas/events{/privacy}","received_events_url":"https://api.github.com/users/dunglas/received_events","type":"User","site_admin":false},"body":"I'm not a fan of having 2 different behaviors depending of the configuration. What do you think about splitting this method in 2 separates methods and throw an error in the method using the serializer if it is not available?","created_at":"2016-02-01T20:54:47Z","updated_at":"2016-02-01T20:54:47Z","html_url":"https://github.com/symfony/symfony/pull/17642#discussion_r51479017","pull_request_url":"https://api.github.com/repos/symfony/symfony/pulls/17642","_links":{"self":{"href":"https://api.github.com/repos/symfony/symfony/pulls/comments/51479017"},"html":{"href":"https://github.com/symfony/symfony/pull/17642#discussion_r51479017"},"pull_request":{"href":"https://api.github.com/repos/symfony/symfony/pulls/17642"}}},"pull_request":{"url":"https://api.github.com/repos/symfony/symfony/pulls/17642","id":57873142,"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","issue_url":"https://api.github.com/repos/symfony/symfony/issues/17642","number":17642,"state":"open","locked":false,"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},"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        | ","created_at":"2016-02-01T17:38:23Z","updated_at":"2016-02-01T20:54:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0d3b4956d24e43624ba1591600220cdb093a08b1","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/symfony/symfony/pulls/17642/commits","review_comments_url":"https://api.github.com/repos/symfony/symfony/pulls/17642/comments","review_comment_url":"https://api.github.com/repos/symfony/symfony/pulls/comments{/number}","comments_url":"https://api.github.com/repos/symfony/symfony/issues/17642/comments","statuses_url":"https://api.github.com/repos/symfony/symfony/statuses/11bc1519d5977599b67ab352bfbf819b69c63f36","head":{"label":"mcfedr:add-controller-json","ref":"add-controller-json","sha":"11bc1519d5977599b67ab352bfbf819b69c63f36","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},"repo":{"id":29537909,"name":"symfony","full_name":"mcfedr/symfony","owner":{"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},"private":false,"html_url":"https://github.com/mcfedr/symfony","description":"The Symfony PHP framework","fork":true,"url":"https://api.github.com/repos/mcfedr/symfony","forks_url":"https://api.github.com/repos/mcfedr/symfony/forks","keys_url":"https://api.github.com/repos/mcfedr/symfony/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mcfedr/symfony/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mcfedr/symfony/teams","hooks_url":"https://api.github.com/repos/mcfedr/symfony/hooks","issue_events_url":"https://api.github.com/repos/mcfedr/symfony/issues/events{/number}","events_url":"https://api.github.com/repos/mcfedr/symfony/events","assignees_url":"https://api.github.com/repos/mcfedr/symfony/assignees{/user}","branches_url":"https://api.github.com/repos/mcfedr/symfony/branches{/branch}","tags_url":"https://api.github.com/repos/mcfedr/symfony/tags","blobs_url":"https://api.github.com/repos/mcfedr/symfony/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mcfedr/symfony/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mcfedr/symfony/git/refs{/sha}","trees_url":"https://api.github.com/repos/mcfedr/symfony/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mcfedr/symfony/statuses/{sha}","languages_url":"https://api.github.com/repos/mcfedr/symfony/languages","stargazers_url":"https://api.github.com/repos/mcfedr/symfony/stargazers","contributors_url":"https://api.github.com/repos/mcfedr/symfony/contributors","subscribers_url":"https://api.github.com/repos/mcfedr/symfony/subscribers","subscription_url":"https://api.github.com/repos/mcfedr/symfony/subscription","commits_url":"https://api.github.com/repos/mcfedr/symfony/commits{/sha}","git_commits_url":"https://api.github.com/repos/mcfedr/symfony/git/commits{/sha}","comments_url":"https://api.github.com/repos/mcfedr/symfony/comments{/number}","issue_comment_url":"https://api.github.com/repos/mcfedr/symfony/issues/comments{/number}","contents_url":"https://api.github.com/repos/mcfedr/symfony/contents/{+path}","compare_url":"https://api.github.com/repos/mcfedr/symfony/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mcfedr/symfony/merges","archive_url":"https://api.github.com/repos/mcfedr/symfony/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mcfedr/symfony/downloads","issues_url":"https://api.github.com/repos/mcfedr/symfony/issues{/number}","pulls_url":"https://api.github.com/repos/mcfedr/symfony/pulls{/number}","milestones_url":"https://api.github.com/repos/mcfedr/symfony/milestones{/number}","notifications_url":"https://api.github.com/repos/mcfedr/symfony/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mcfedr/symfony/labels{/name}","releases_url":"https://api.github.com/repos/mcfedr/symfony/releases{/id}","deployments_url":"https://api.github.com/repos/mcfedr/symfony/deployments","created_at":"2015-01-20T15:56:44Z","updated_at":"2015-01-20T15:56:57Z","pushed_at":"2016-02-01T20:40:57Z","git_url":"git://github.com/mcfedr/symfony.git","ssh_url":"git@github.com:mcfedr/symfony.git","clone_url":"https://github.com/mcfedr/symfony.git","svn_url":"https://github.com/mcfedr/symfony","homepage":"symfony.com","size":66015,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":false,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"2.7"}},"base":{"label":"symfony:master","ref":"master","sha":"83b53f4a89fa2f436ba0f8d88b0714aa534b2cd2","user":{"login":"symfony","id":143937,"avatar_url":"https://avatars.githubusercontent.com/u/143937?v=3","gravatar_id":"","url":"https://api.github.com/users/symfony","html_url":"https://github.com/symfony","followers_url":"https://api.github.com/users/symfony/followers","following_url":"https://api.github.com/users/symfony/following{/other_user}","gists_url":"https://api.github.com/users/symfony/gists{/gist_id}","starred_url":"https://api.github.com/users/symfony/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/symfony/subscriptions","organizations_url":"https://api.github.com/users/symfony/orgs","repos_url":"https://api.github.com/users/symfony/repos","events_url":"https://api.github.com/users/symfony/events{/privacy}","received_events_url":"https://api.github.com/users/symfony/received_events","type":"Organization","site_admin":false},"repo":{"id":458058,"name":"symfony","full_name":"symfony/symfony","owner":{"login":"symfony","id":143937,"avatar_url":"https://avatars.githubusercontent.com/u/143937?v=3","gravatar_id":"","url":"https://api.github.com/users/symfony","html_url":"https://github.com/symfony","followers_url":"https://api.github.com/users/symfony/followers","following_url":"https://api.github.com/users/symfony/following{/other_user}","gists_url":"https://api.github.com/users/symfony/gists{/gist_id}","starred_url":"https://api.github.com/users/symfony/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/symfony/subscriptions","organizations_url":"https://api.github.com/users/symfony/orgs","repos_url":"https://api.github.com/users/symfony/repos","events_url":"https://api.github.com/users/symfony/events{/privacy}","received_events_url":"https://api.github.com/users/symfony/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/symfony/symfony","description":"The Symfony PHP framework","fork":false,"url":"https://api.github.com/repos/symfony/symfony","forks_url":"https://api.github.com/repos/symfony/symfony/forks","keys_url":"https://api.github.com/repos/symfony/symfony/keys{/key_id}","collaborators_url":"https://api.github.com/repos/symfony/symfony/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/symfony/symfony/teams","hooks_url":"https://api.github.com/repos/symfony/symfony/hooks","issue_events_url":"https://api.github.com/repos/symfony/symfony/issues/events{/number}","events_url":"https://api.github.com/repos/symfony/symfony/events","assignees_url":"https://api.github.com/repos/symfony/symfony/assignees{/user}","branches_url":"https://api.github.com/repos/symfony/symfony/branches{/branch}","tags_url":"https://api.github.com/repos/symfony/symfony/tags","blobs_url":"https://api.github.com/repos/symfony/symfony/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/symfony/symfony/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/symfony/symfony/git/refs{/sha}","trees_url":"https://api.github.com/repos/symfony/symfony/git/trees{/sha}","statuses_url":"https://api.github.com/repos/symfony/symfony/statuses/{sha}","languages_url":"https://api.github.com/repos/symfony/symfony/languages","stargazers_url":"https://api.github.com/repos/symfony/symfony/stargazers","contributors_url":"https://api.github.com/repos/symfony/symfony/contributors","subscribers_url":"https://api.github.com/repos/symfony/symfony/subscribers","subscription_url":"https://api.github.com/repos/symfony/symfony/subscription","commits_url":"https://api.github.com/repos/symfony/symfony/commits{/sha}","git_commits_url":"https://api.github.com/repos/symfony/symfony/git/commits{/sha}","comments_url":"https://api.github.com/repos/symfony/symfony/comments{/number}","issue_comment_url":"https://api.github.com/repos/symfony/symfony/issues/comments{/number}","contents_url":"https://api.github.com/repos/symfony/symfony/contents/{+path}","compare_url":"https://api.github.com/repos/symfony/symfony/compare/{base}...{head}","merges_url":"https://api.github.com/repos/symfony/symfony/merges","archive_url":"https://api.github.com/repos/symfony/symfony/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/symfony/symfony/downloads","issues_url":"https://api.github.com/repos/symfony/symfony/issues{/number}","pulls_url":"https://api.github.com/repos/symfony/symfony/pulls{/number}","milestones_url":"https://api.github.com/repos/symfony/symfony/milestones{/number}","notifications_url":"https://api.github.com/repos/symfony/symfony/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/symfony/symfony/labels{/name}","releases_url":"https://api.github.com/repos/symfony/symfony/releases{/id}","deployments_url":"https://api.github.com/repos/symfony/symfony/deployments","created_at":"2010-01-04T14:21:21Z","updated_at":"2016-02-01T20:29:49Z","pushed_at":"2016-02-01T20:47:38Z","git_url":"git://github.com/symfony/symfony.git","ssh_url":"git@github.com:symfony/symfony.git","clone_url":"https://github.com/symfony/symfony.git","svn_url":"https://github.com/symfony/symfony","homepage":"symfony.com","size":100376,"stargazers_count":11651,"watchers_count":11651,"language":"PHP","has_issues":true,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":4580,"mirror_url":null,"open_issues_count":782,"forks":4580,"open_issues":782,"watchers":11651,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/symfony/symfony/pulls/17642"},"html":{"href":"https://github.com/symfony/symfony/pull/17642"},"issue":{"href":"https://api.github.com/repos/symfony/symfony/issues/17642"},"comments":{"href":"https://api.github.com/repos/symfony/symfony/issues/17642/comments"},"review_comments":{"href":"https://api.github.com/repos/symfony/symfony/pulls/17642/comments"},"review_comment":{"href":"https://api.github.com/repos/symfony/symfony/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/symfony/symfony/pulls/17642/commits"},"statuses":{"href":"https://api.github.com/repos/symfony/symfony/statuses/11bc1519d5977599b67ab352bfbf819b69c63f36"}}}}