{"action":"created","comment":{"url":"https://api.github.com/repos/brettminnie/breakfast-serializer/pulls/comments/29035848","id":29035848,"diff_hunk":"@@ -0,0 +1,155 @@\n+<?php\n+\n+namespace BDBStudios\\BreakfastSerializer;\n+\n+/**\n+ * Class JSONSerializer\n+ * @package BDBStudios\\BreakfastSerializer\n+ */\n+class JSONSerializer extends Serializer implements IsSerializable, IsDepthTraversable\n+{\n+\n+    public function __construct()\n+    {\n+        parent::__construct(self::FORMAT_JSON);\n+    }\n+\n+    /**\n+     * @inheritdoc\n+     */\n+    public function deserialize($data)\n+    {\n+        $data = json_decode($data, true);\n+\n+        return $this->arrayToObject(\n+            $data\n+        );\n+    }\n+\n+    /**\n+     * @inheritdoc\n+     */\n+    public function serialize($data)\n+    {\n+        return json_encode(\n+            $this->objectToArray(\n+                $data\n+            )\n+        );\n+    }\n+\n+    /**\n+     * @param array $data\n+     * @return mixed\n+     * @throws \\Exception\n+     * @todo refactor this out somewhere once we start implementing in new formats\n+     */\n+    protected function arrayToObject(array $data)\n+    {\n+        $object     = new $data['className']();\n+        $reflection = new \\ReflectionClass($data['className']);\n+        $breadth    = array();\n+\n+        $object = $this->extractAndSetSingleDepthProperties($data, $breadth, $reflection, $object);\n+        $object = $this->extractAndSetMultipleDepthProperties($breadth, $reflection, $object);\n+\n+        return $object;\n+    }\n+\n+    /**\n+     * @param array $data\n+     * @param array $breadth\n+     * @param \\ReflectionClass $reflection\n+     * @param mixed $object\n+     * @return mixed\n+     * @throws \\Exception\n+     * @todo refactor this out somewhere once we start implementing in new formats\n+     */\n+    protected function extractAndSetSingleDepthProperties(\n+        array $data,\n+        array& $breadth,\n+        \\ReflectionClass& $reflection,\n+        $object\n+    )\n+    {\n+        foreach($data as $key=>$value) {\n+            if (true === is_array($value)) {\n+                $breadth[$key] = $value;\n+            } else {\n+                try {\n+                    $property = $reflection->getProperty($key);\n+                    $property->setAccessible(true);\n+                    $property->setValue($object, $value);\n+                } catch (\\ReflectionException $e) {\n+                    //Non property so we ignore this\n+                } catch (\\Exception $e) {\n+                    throw $e;\n+                }\n+            }\n+        }\n+\n+        return $object;\n+    }\n+\n+    /**\n+     * @param array $breadth\n+     * @param \\ReflectionClass $reflection\n+     * @param mixed $object\n+     * @return mixed\n+     * @throws \\Exception\n+     * @todo refactor this out somewhere once we start implementing in new formats\n+     */\n+    protected function extractAndSetMultipleDepthProperties(\n+        array& $breadth,\n+        \\ReflectionClass& $reflection,\n+        $object\n+    )\n+    {\n+        $propertyData = array();\n+\n+        foreach($breadth as $key => $value) {\n+            foreach ($value as $instance) {\n+                $propertyData[] = $this->arrayToObject($instance);\n+            }\n+\n+            try {\n+                $property = $reflection->getProperty($key);\n+                $property->setAccessible(true);\n+                $property->setValue($object, $propertyData);\n+            } catch (\\ReflectionException $e) {\n+                //Non property so we ignore this\n+                throw $e;\n+            }\n+        }\n+\n+        return $object;\n+    }\n+\n+    /**\n+     * @param mixed $baseObject\n+     * @param bool  $exposeClassName\n+     * @return array\n+     * @todo refactor this out somewhere once we start implementing in new formats\n+     */\n+    protected function objectToArray($baseObject, $exposeClassName = true)\n+    {\n+        $data = array();\n+\n+        $objAsArray = is_object($baseObject) ? (array)$baseObject : $baseObject;\n+\n+        if (true === SerializerFactory::canIterate($objAsArray)) {\n+            foreach ($objAsArray as $key => $val) {\n+                $val =\n+                    (is_array($val) || is_object($val)) ? $this->objectToArray($val, $exposeClassName) : $val;","path":"src/BreakfastSerializer/JSONSerializer.php","position":143,"original_position":143,"commit_id":"182f74633a70b521a5d6e6e67d1a621631983eed","original_commit_id":"ab00f2212457ec25da688cfcf694b3e64ecf9e95","user":{"login":"brettminnie","id":6124248,"avatar_url":"https://avatars.githubusercontent.com/u/6124248?v=3","gravatar_id":"","url":"https://api.github.com/users/brettminnie","html_url":"https://github.com/brettminnie","followers_url":"https://api.github.com/users/brettminnie/followers","following_url":"https://api.github.com/users/brettminnie/following{/other_user}","gists_url":"https://api.github.com/users/brettminnie/gists{/gist_id}","starred_url":"https://api.github.com/users/brettminnie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brettminnie/subscriptions","organizations_url":"https://api.github.com/users/brettminnie/orgs","repos_url":"https://api.github.com/users/brettminnie/repos","events_url":"https://api.github.com/users/brettminnie/events{/privacy}","received_events_url":"https://api.github.com/users/brettminnie/received_events","type":"User","site_admin":false},"body":"aah ok, no that makes sense, I'll go with ease of readability\r\n","created_at":"2015-04-24T09:32:17Z","updated_at":"2015-04-24T09:32:17Z","html_url":"https://github.com/brettminnie/breakfast-serializer/pull/10#discussion_r29035848","pull_request_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/pulls/10","_links":{"self":{"href":"https://api.github.com/repos/brettminnie/breakfast-serializer/pulls/comments/29035848"},"html":{"href":"https://github.com/brettminnie/breakfast-serializer/pull/10#discussion_r29035848"},"pull_request":{"href":"https://api.github.com/repos/brettminnie/breakfast-serializer/pulls/10"}}},"pull_request":{"url":"https://api.github.com/repos/brettminnie/breakfast-serializer/pulls/10","id":34028996,"html_url":"https://github.com/brettminnie/breakfast-serializer/pull/10","diff_url":"https://github.com/brettminnie/breakfast-serializer/pull/10.diff","patch_url":"https://github.com/brettminnie/breakfast-serializer/pull/10.patch","issue_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/issues/10","number":10,"state":"open","locked":false,"title":"Feature/create serializer factory","user":{"login":"brettminnie","id":6124248,"avatar_url":"https://avatars.githubusercontent.com/u/6124248?v=3","gravatar_id":"","url":"https://api.github.com/users/brettminnie","html_url":"https://github.com/brettminnie","followers_url":"https://api.github.com/users/brettminnie/followers","following_url":"https://api.github.com/users/brettminnie/following{/other_user}","gists_url":"https://api.github.com/users/brettminnie/gists{/gist_id}","starred_url":"https://api.github.com/users/brettminnie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brettminnie/subscriptions","organizations_url":"https://api.github.com/users/brettminnie/orgs","repos_url":"https://api.github.com/users/brettminnie/repos","events_url":"https://api.github.com/users/brettminnie/events{/privacy}","received_events_url":"https://api.github.com/users/brettminnie/received_events","type":"User","site_admin":false},"body":"Will close #9 ","created_at":"2015-04-24T08:44:26Z","updated_at":"2015-04-24T09:32:17Z","closed_at":null,"merged_at":null,"merge_commit_sha":"52270b2f87b45e51917fdc1298d5cbca53e5cd03","assignee":{"login":"eddiejaoude","id":624760,"avatar_url":"https://avatars.githubusercontent.com/u/624760?v=3","gravatar_id":"","url":"https://api.github.com/users/eddiejaoude","html_url":"https://github.com/eddiejaoude","followers_url":"https://api.github.com/users/eddiejaoude/followers","following_url":"https://api.github.com/users/eddiejaoude/following{/other_user}","gists_url":"https://api.github.com/users/eddiejaoude/gists{/gist_id}","starred_url":"https://api.github.com/users/eddiejaoude/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eddiejaoude/subscriptions","organizations_url":"https://api.github.com/users/eddiejaoude/orgs","repos_url":"https://api.github.com/users/eddiejaoude/repos","events_url":"https://api.github.com/users/eddiejaoude/events{/privacy}","received_events_url":"https://api.github.com/users/eddiejaoude/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/brettminnie/breakfast-serializer/milestones/1","html_url":"https://github.com/brettminnie/breakfast-serializer/milestones/v0.1%20Initial%20Alpha","labels_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/milestones/1/labels","id":1078988,"number":1,"title":"v0.1 Initial Alpha","description":"Make it work with json","creator":{"login":"brettminnie","id":6124248,"avatar_url":"https://avatars.githubusercontent.com/u/6124248?v=3","gravatar_id":"","url":"https://api.github.com/users/brettminnie","html_url":"https://github.com/brettminnie","followers_url":"https://api.github.com/users/brettminnie/followers","following_url":"https://api.github.com/users/brettminnie/following{/other_user}","gists_url":"https://api.github.com/users/brettminnie/gists{/gist_id}","starred_url":"https://api.github.com/users/brettminnie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brettminnie/subscriptions","organizations_url":"https://api.github.com/users/brettminnie/orgs","repos_url":"https://api.github.com/users/brettminnie/repos","events_url":"https://api.github.com/users/brettminnie/events{/privacy}","received_events_url":"https://api.github.com/users/brettminnie/received_events","type":"User","site_admin":false},"open_issues":5,"closed_issues":3,"state":"open","created_at":"2015-04-22T14:31:33Z","updated_at":"2015-04-24T08:44:31Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/pulls/10/commits","review_comments_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/pulls/10/comments","review_comment_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/pulls/comments{/number}","comments_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/issues/10/comments","statuses_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/statuses/182f74633a70b521a5d6e6e67d1a621631983eed","head":{"label":"brettminnie:feature/createSerializerFactory","ref":"feature/createSerializerFactory","sha":"182f74633a70b521a5d6e6e67d1a621631983eed","user":{"login":"brettminnie","id":6124248,"avatar_url":"https://avatars.githubusercontent.com/u/6124248?v=3","gravatar_id":"","url":"https://api.github.com/users/brettminnie","html_url":"https://github.com/brettminnie","followers_url":"https://api.github.com/users/brettminnie/followers","following_url":"https://api.github.com/users/brettminnie/following{/other_user}","gists_url":"https://api.github.com/users/brettminnie/gists{/gist_id}","starred_url":"https://api.github.com/users/brettminnie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brettminnie/subscriptions","organizations_url":"https://api.github.com/users/brettminnie/orgs","repos_url":"https://api.github.com/users/brettminnie/repos","events_url":"https://api.github.com/users/brettminnie/events{/privacy}","received_events_url":"https://api.github.com/users/brettminnie/received_events","type":"User","site_admin":false},"repo":{"id":33876292,"name":"breakfast-serializer","full_name":"brettminnie/breakfast-serializer","owner":{"login":"brettminnie","id":6124248,"avatar_url":"https://avatars.githubusercontent.com/u/6124248?v=3","gravatar_id":"","url":"https://api.github.com/users/brettminnie","html_url":"https://github.com/brettminnie","followers_url":"https://api.github.com/users/brettminnie/followers","following_url":"https://api.github.com/users/brettminnie/following{/other_user}","gists_url":"https://api.github.com/users/brettminnie/gists{/gist_id}","starred_url":"https://api.github.com/users/brettminnie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brettminnie/subscriptions","organizations_url":"https://api.github.com/users/brettminnie/orgs","repos_url":"https://api.github.com/users/brettminnie/repos","events_url":"https://api.github.com/users/brettminnie/events{/privacy}","received_events_url":"https://api.github.com/users/brettminnie/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/brettminnie/breakfast-serializer","description":"A (hopefully) backwards compatible replacement for the JMS serializer","fork":false,"url":"https://api.github.com/repos/brettminnie/breakfast-serializer","forks_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/forks","keys_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/keys{/key_id}","collaborators_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/teams","hooks_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/hooks","issue_events_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/issues/events{/number}","events_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/events","assignees_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/assignees{/user}","branches_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/branches{/branch}","tags_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/tags","blobs_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/git/refs{/sha}","trees_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/git/trees{/sha}","statuses_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/statuses/{sha}","languages_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/languages","stargazers_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/stargazers","contributors_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/contributors","subscribers_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/subscribers","subscription_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/subscription","commits_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/commits{/sha}","git_commits_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/git/commits{/sha}","comments_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/comments{/number}","issue_comment_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/issues/comments{/number}","contents_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/contents/{+path}","compare_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/compare/{base}...{head}","merges_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/merges","archive_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/downloads","issues_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/issues{/number}","pulls_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/pulls{/number}","milestones_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/milestones{/number}","notifications_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/labels{/name}","releases_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/releases{/id}","created_at":"2015-04-13T15:21:18Z","updated_at":"2015-04-22T19:32:30Z","pushed_at":"2015-04-24T09:25:20Z","git_url":"git://github.com/brettminnie/breakfast-serializer.git","ssh_url":"git@github.com:brettminnie/breakfast-serializer.git","clone_url":"https://github.com/brettminnie/breakfast-serializer.git","svn_url":"https://github.com/brettminnie/breakfast-serializer","homepage":null,"size":186,"stargazers_count":1,"watchers_count":1,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":5,"forks":0,"open_issues":5,"watchers":1,"default_branch":"develop"}},"base":{"label":"brettminnie:develop","ref":"develop","sha":"d3696c75c3e0294ac9251da6fcecd7c716787731","user":{"login":"brettminnie","id":6124248,"avatar_url":"https://avatars.githubusercontent.com/u/6124248?v=3","gravatar_id":"","url":"https://api.github.com/users/brettminnie","html_url":"https://github.com/brettminnie","followers_url":"https://api.github.com/users/brettminnie/followers","following_url":"https://api.github.com/users/brettminnie/following{/other_user}","gists_url":"https://api.github.com/users/brettminnie/gists{/gist_id}","starred_url":"https://api.github.com/users/brettminnie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brettminnie/subscriptions","organizations_url":"https://api.github.com/users/brettminnie/orgs","repos_url":"https://api.github.com/users/brettminnie/repos","events_url":"https://api.github.com/users/brettminnie/events{/privacy}","received_events_url":"https://api.github.com/users/brettminnie/received_events","type":"User","site_admin":false},"repo":{"id":33876292,"name":"breakfast-serializer","full_name":"brettminnie/breakfast-serializer","owner":{"login":"brettminnie","id":6124248,"avatar_url":"https://avatars.githubusercontent.com/u/6124248?v=3","gravatar_id":"","url":"https://api.github.com/users/brettminnie","html_url":"https://github.com/brettminnie","followers_url":"https://api.github.com/users/brettminnie/followers","following_url":"https://api.github.com/users/brettminnie/following{/other_user}","gists_url":"https://api.github.com/users/brettminnie/gists{/gist_id}","starred_url":"https://api.github.com/users/brettminnie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brettminnie/subscriptions","organizations_url":"https://api.github.com/users/brettminnie/orgs","repos_url":"https://api.github.com/users/brettminnie/repos","events_url":"https://api.github.com/users/brettminnie/events{/privacy}","received_events_url":"https://api.github.com/users/brettminnie/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/brettminnie/breakfast-serializer","description":"A (hopefully) backwards compatible replacement for the JMS serializer","fork":false,"url":"https://api.github.com/repos/brettminnie/breakfast-serializer","forks_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/forks","keys_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/keys{/key_id}","collaborators_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/teams","hooks_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/hooks","issue_events_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/issues/events{/number}","events_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/events","assignees_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/assignees{/user}","branches_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/branches{/branch}","tags_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/tags","blobs_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/git/refs{/sha}","trees_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/git/trees{/sha}","statuses_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/statuses/{sha}","languages_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/languages","stargazers_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/stargazers","contributors_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/contributors","subscribers_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/subscribers","subscription_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/subscription","commits_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/commits{/sha}","git_commits_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/git/commits{/sha}","comments_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/comments{/number}","issue_comment_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/issues/comments{/number}","contents_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/contents/{+path}","compare_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/compare/{base}...{head}","merges_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/merges","archive_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/downloads","issues_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/issues{/number}","pulls_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/pulls{/number}","milestones_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/milestones{/number}","notifications_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/labels{/name}","releases_url":"https://api.github.com/repos/brettminnie/breakfast-serializer/releases{/id}","created_at":"2015-04-13T15:21:18Z","updated_at":"2015-04-22T19:32:30Z","pushed_at":"2015-04-24T09:25:20Z","git_url":"git://github.com/brettminnie/breakfast-serializer.git","ssh_url":"git@github.com:brettminnie/breakfast-serializer.git","clone_url":"https://github.com/brettminnie/breakfast-serializer.git","svn_url":"https://github.com/brettminnie/breakfast-serializer","homepage":null,"size":186,"stargazers_count":1,"watchers_count":1,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":5,"forks":0,"open_issues":5,"watchers":1,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/brettminnie/breakfast-serializer/pulls/10"},"html":{"href":"https://github.com/brettminnie/breakfast-serializer/pull/10"},"issue":{"href":"https://api.github.com/repos/brettminnie/breakfast-serializer/issues/10"},"comments":{"href":"https://api.github.com/repos/brettminnie/breakfast-serializer/issues/10/comments"},"review_comments":{"href":"https://api.github.com/repos/brettminnie/breakfast-serializer/pulls/10/comments"},"review_comment":{"href":"https://api.github.com/repos/brettminnie/breakfast-serializer/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/brettminnie/breakfast-serializer/pulls/10/commits"},"statuses":{"href":"https://api.github.com/repos/brettminnie/breakfast-serializer/statuses/182f74633a70b521a5d6e6e67d1a621631983eed"}}}}