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
.