You are here

public function EntityToJsonApi::serialize in JSON:API 8

Return the requested entity as a raw string.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity to generate the JSON from.

Return value

string The raw JSON string of the requested resource.

File

src/EntityToJsonApi.php, line 89

Class

EntityToJsonApi
Simplifies the process of generating a JSON API version of an entity.

Namespace

Drupal\jsonapi

Code

public function serialize(EntityInterface $entity) {

  // TODO: Supporting includes requires adding the 'include' query string.
  return $this->serializer
    ->serialize(new JsonApiDocumentTopLevel($entity), 'api_json', $this
    ->calculateContext($entity));
}