// @see \Drupal\jsonapi\EventSubscriber\DefaultExceptionSubscriber::isJsonApiExceptionEvent()
$context = !
$response->
isSuccessful() ?
[] :
static::
generateContext($request);
$jsonapi_doc_object =
$serializer->
normalize($data,
$format,
$context);
// Having just normalized the data, we can associate its cacheability with
// the response object.
if ($response instanceof CacheableResponseInterface
) { assert($jsonapi_doc_object instanceof CacheableNormalization
);
$response->
addCacheableDependency($jsonapi_doc_object);
} // Finally, encode the normalized data (JSON:API's encoder rasterizes it
// automatically).
$response->
setContent($serializer->
encode($jsonapi_doc_object->
getNormalization(),
$format));
$response->headers->
set('Content-Type',
$request->
getMimeType($format));
} } /**
* Generates a top-level JSON:API normalization context.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The request from which the context can be derived.
*
* @return array
* The generated context.
*/