zf-fr/zfr-rest — pull request #114 by bakura10 (2014-01-14 11:28:30+00:00)
Title: Remove automatic serialization

Hi,

ping @Ocramius @danizord

As discussed with @danizord, there are two main problems with the current automatic serialization. For remind, the current way is either directly returns the entity (for instance a User) or a paginator. The ResourceRenderer then automatically use the hydrator to extract data, or add metadata if it detects a paginator was found.

This has two problems:

* It's hard to customize the way the output is serialized. For instance you may want to have underscore_separated keys, and wrapping all the items inside a "items" key in the payload.
* You may want to add other data that are computed and actually don't belong to the entity itself. For instance, the GitHub API (https://api.github.com/users/danizord) adds data like "public_repos" that don't really belong to the entity itself (I suppose those are fetched from a repository and added to the payload). Because the hydrator is used, it makes it nearly impossible.

Therefore, albeit convenient, all this automation is hard to use in a lot of cases. This PR completely removes any automation, so the serialization has to be done in the controller directly:

```php
public function get(User $user)
{
return ['username' => $user->getUsername()]; // ...
}
```

Note that this solution is far from optimal, because now everything has to be done manually. Furthermore, a lot of duplication is done (there is great chance that the "get" method of the UsersCollectionController will do the same thing).