Issues

ZF2-400: ViewJsonStrategy

Description

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 -> http://akrabat.com/zend-framework-2/…

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.

Comments

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 (https://gist.github.com/cd57d65055cde28af80c). It is a known issue that is being worked on (ref: https://twitter.com/Freeaqingme/status/…)

Resolved with: https://github.com/zendframework/zf2/pull/1930

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