code: protected function serializeDataProvider($dataProvider)
      {
          if ($this->preserveKeys) {
              $models = $dataProvider->getModels();
          } else {
              $models = array_values($dataProvider->getModels());
          }
          $models = $this->serializeModels($models);
  
          if (($pagination = $dataProvider->getPagination()) !== false) {
              $this->addPaginationHeaders($pagination);
          }
  
          if ($this->request->getIsHead()) {
              return null;
          } elseif ($this->collectionEnvelope === null) {
              return $models;
          }
  
          $result = [
              $this->collectionEnvelope => $models,
          ];
          if ($pagination !== false) {
              return array_merge($result, $this->serializePagination($pagination));
          }
  
          return $result;
      }
docs: Serializes a data provider.
  @param DataProviderInterface $dataProvider
  @return array the array representation of the data provider.