Doctrine2, PersistentCollection and JMS Serializer

一曲冷凌霜 提交于 2019-12-01 11:46:52

The PersistentCollection object is an Iterator Aggregate and not an array. The distinction is that an Iterator is an object that can be iterated over and so may or may not contain the data required for serializing to an array at any one time.

To serialize the Collection as JSON, try the following:

$serializer = $container->get('serializer');
$arr        = $this->getQueuedItems()->toArray();
$json       = $serializer->serialize($arr, 'json');

If you're not too fussed about the keys, you could also use getValues, rather than toArray.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!