You are here

public function EntityToJsonApi::normalize in JSON:API 8

Return the requested entity as an structured array.

Parameters

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

Return value

array The JSON structure of the requested resource.

File

src/EntityToJsonApi.php, line 106

Class

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

Namespace

Drupal\jsonapi

Code

public function normalize(EntityInterface $entity) {
  return $this->serializer
    ->normalize(new JsonApiDocumentTopLevel($entity), 'api_json', $this
    ->calculateContext($entity))
    ->rasterizeValue();
}