zfcampus/zf-hal — pull request #39 by weierophinney (2014-07-16 16:28:26+00:00)
Title: Can't return a collection object with embedded entities when content negotiation is set to Json

Possible resolution as mentioned below:
```
okay, it looks like we don't allow you to replace the collection at any point currently! I think we may need to change that.
```
Transcript from IRC:
```
weierophinney: on a resource's fetchAll with Json content negotiation, how would you return a collection of entities with extra attributes (e.g. total_items, as with HalJson)?
djule5: wrap them as an array embedded in another object, and have those properties either as public, or make that object JsonSerializable.
weierophinney: that's exactly what I'm doing, but the api call returns me an empty Json array... I was confused because I knew I was returning the data correctly at the end of the fetchAll call... but I just found out what's happening, and it's in ZF\Rest\Resource::fetchAll()... basically if the returned value from the fetchAll call is not an array, HalCollection or Traversable, an empty array is returned. Is that the correct behavior?
djule5: yes -- because RestController will then cast the array to a HalCollection.
weierophinney: so how is your suggestion supposed to work in this case? If I return an object, an empty array is being returned (what I'm getting right now)
djule5: hmmmm... trying to figure out a way to manipulate it. I thought you'd be able to via the Resource's events or the RestController's events, but I'm not seeing a way. Going to look in zf-hal in a momemnt.
djule5: okay, it looks like we don't allow you to replace the collection at any point currently! I think we may need to change that. Can you raise an issue on each of zf-rest and zf-hal about that for me?
weierophinney: that's what I thought too! ;) and I'd really like to be able to use collection objects to accomplish this. So yes I will raise the issue on both repos :) thanks!
```