ZF2-400: ViewJsonStrategy


I can't find exactly what changed in Beta 5 but in Beta 4 this worked great, now it appears to be broken.

I'd like to use the ViewJsonStrategy via JsonModel(). Using the example that worked in Beta 4 found here ->…

However, the problem here is as of Beta 5 when you add the following to the view_manager in ANY module config/module.config.php file it breaks ALL modules: 'strategies' => array('ViewJsonStrategy')

The results you get are: {"content":[]}

I thought perhaps I was doing something wrong so I returned to Beta 4 and recreated the Skeleton App and added the ZF2 library and it worked. So I decided to go back to Beta 5 and do the exact same thing by cloning the most up2date SkeletonApp and ZF2 Library and the problem exists here.

If you have any additional modules, the {"content":[]} will also show up on those modules too, it's not just contained within a single module. So it renders your entire application void until you remove the 'strategies' => array('ViewJsonStrategy') from the view_manager.

If something did change in Beta 5 that would help resolve this I'd love to know how to go about making it work again.


I can confirm this. The ViewJsonStrategy will always be selected, regardless of what view model is returned in the controller. The check for the accept header doesn't work with Firefox because it adds / to the accept header.

I have experienced this as well ( It is a known issue that is being worked on (ref:…)

Resolved with:

will only choose JsonStrategy for application/json or application/javascript