protected function getSerializedResponse($action, $result, $params)
    {
        $dataProvider = null;
        if ($result instanceof DataProviderInterface) {
            $dataProvider = $result;
        } elseif (isset($result['dataProvider']) && $result['dataProvider'] instanceof DataProviderInterface) {
            $dataProvider = $result['dataProvider'];
        }
        if ($dataProvider !== null
            && ($dataProvider->getPagination() !== false
                || $dataProvider->getTotalCount() >= self::SERIALIZATION_LIMIT)
            && $dataProvider->getPagination()->getPageSize() >= self::SERIALIZATION_LIMIT
        ) {
            return false;
        }

        if (isset($result['dataProvider'])) {
            $data = $result['dataProvider'];
        } elseif (isset($result['model'])) {
            $data = $result['model'];
        } else {
            $data = $result;
        }
        $data = parent::afterAction($action, $data);
        return Yii::createObject($this->serializer)->serialize($data);
    }