title: How to serialize slice of ArrayCollection using JMS Serializer?
body: <p>I want to serialize into JSON entity <code>Category</code> with collection of <code>Presentation</code> entities (see below) to use for REST API.</p>
  
  <p>The endpoint will look something like this <code>/api/v1/categories/1</code> </p>
  
  <p>When dataset is small and when <code>Category</code> only has only 5-10 related <code>Presentations</code> then the resulting response is not too large. However when <code>Category</code> starts to have let's say 100 or 200 related <code>Presentations</code> then obviously I do not want to return all of them, but would like to "paginate" the results, eg. when calling endpoint:</p>
  
  <p><code>/api/v1/categories/1?page=2</code>  - would return only "2nd page"</p>
  
  <p><code>/api/v1/categories/1/page=3</code>  - would return "3rd page"</p>
  
  <p>or even it can be with <code>offset</code> and <code>limit</code>:</p>
  
  <p><code>/api/v1/categories/1?offset=20&amp;limit=10</code> </p>
  
  <p>but the problem is: <strong>how to make JMS serializer serialize only a slice of the collection?</strong></p>
  
  <pre><code>/**
   * @ORM\Entity(repositoryClass="AppBundle\Repository\CategoryRepository")
   */
  class Category
  {
  
      /**
       * @var string
       * @ORM\Column(type="string")
       * @JMS\Expose()
       * @JMS\Groups({"get-category"})
       */
      private $title;
  
  
      // ...
  
      /**
       * @var ArrayCollection
       * @ORM\ManyToMany(targetEntity="AppBundle\Entity\Presentation", mappedBy="categories", fetch="EXTRA_LAZY")
       * @JMS\Groups({"get-category"})
       * @JMS\Expose()
       */
      private $presentations;
  
  
      // ...
  
  }
  </code></pre>
  
  <p>ps. I know that for example if I want to get always <strong>first</strong> 5 elements of the collection, I can add created <code>@VirtualProperty</code> and slice the doctrine <code>ArrayCollection</code> as shown below. But the problem here is that I cannot pass the offset parameters to this method. As it would be called internally by JMSSerializer somewhere...</p>
  
  <pre><code>/**
   * @JMS\VirtualProperty()
   *
   */
  public function getFirstFivePresentations(){
      return $this-&gt;presentations-&gt;slice(0,5);
  }
  </code></pre>