diff --git a/src/Hal/Serializer/ItemNormalizer.php b/src/Hal/Serializer/ItemNormalizer.php index 8c33a9522b4..9305d6f5d28 100644 --- a/src/Hal/Serializer/ItemNormalizer.php +++ b/src/Hal/Serializer/ItemNormalizer.php @@ -30,6 +30,7 @@ final class ItemNormalizer extends AbstractItemNormalizer const FORMAT = 'jsonhal'; private $componentsCache = []; + private $attributesMetadataCache = []; /** * {@inheritdoc} @@ -169,7 +170,10 @@ private function getComponents($object, string $format = null, array $context) private function populateRelation(array $data, $object, string $format = null, array $context, array $components, string $type): array { $class = \get_class($object); - $attributesMetadata = $this->classMetadataFactory ? $this->classMetadataFactory->getMetadataFor($object)->getAttributesMetadata() : null; + + $attributesMetadata = \array_key_exists($class, $this->attributesMetadataCache) ? + $this->attributesMetadataCache[$class] : + $this->attributesMetadataCache[$class] = $this->classMetadataFactory ? $this->classMetadataFactory->getMetadataFor($object)->getAttributesMetadata() : null; $key = '_'.$type; foreach ($components[$type] as $relation) {