protected function serializeResource(FractalSerializerAbstract $serializer, $data)
    {
        $resourceKey = $this->resource->getResourceKey();

        if ($this->resource instanceof FractalCollection) {
            return $serializer->collection($resourceKey, $data);
        } elseif ($this->resource instanceof FractalItem) {
            return $serializer->item($resourceKey, $data);
        } elseif ($this->resource instanceof NodesResourceContent) {
            return (! empty($resourceKey)) ? [$resourceKey => $data] : $data;
        }

        return $serializer->null();
    }