decoratedSerializer = $serializer; } /** * Lazily initializes the fallback serializer for the JSON API serializer. * * Breaks circular dependency. */ protected function lazilyInitialize() { if (!$this->isInitialized) { $core_serializer = \Drupal::service('serializer'); $this->decoratedSerializer->setFallbackNormalizer($core_serializer); $this->isInitialized = TRUE; } } /** * Relays a method call to the decorated service. * * @param string $method_name * The method to invoke on the decorated serializer. * @param array $args * The arguments to pass to the invoked method on the decorated serializer. * * @return mixed * The return value. */ protected function relay($method_name, array $args) { $this->lazilyInitialize(); return call_user_func_array([$this->decoratedSerializer, $method_name], $args); } /** * {@inheritdoc} */ public function decode($data, $format, array $context = []) { return $this->relay(__FUNCTION__, func_get_args()); } /** * {@inheritdoc} */ public function denormalize($data, $class, $format = NULL, array $context = []) { return $this->relay(__FUNCTION__, func_get_args()); } /** * {@inheritdoc} */ public function deserialize($data, $type, $format, array $context = []) { return $this->relay(__FUNCTION__, func_get_args()); } /** * {@inheritdoc} */ public function encode($data, $format, array $context = []) { return $this->relay(__FUNCTION__, func_get_args()); } /** * {@inheritdoc} */ public function normalize($object, $format = NULL, array $context = []) { return $this->relay(__FUNCTION__, func_get_args()); } /** * {@inheritdoc} */ public function supportsDecoding($format) { return $this->relay(__FUNCTION__, func_get_args()); } /** * {@inheritdoc} */ public function serialize($data, $format, array $context = []) { return $this->relay(__FUNCTION__, func_get_args()); } /** * {@inheritdoc} */ public function supportsDenormalization($data, $type, $format = NULL) { return $this->relay(__FUNCTION__, func_get_args()); } /** * {@inheritdoc} */ public function supportsEncoding($format) { return $this->relay(__FUNCTION__, func_get_args()); } /** * {@inheritdoc} */ public function supportsNormalization($data, $format = NULL) { return $this->relay(__FUNCTION__, func_get_args()); } }