protected function getAttributeValue($object, $attribute, $format = null, array $context = [])
{
$propertyMetadata = $this->propertyMetadataFactory->create($context['resource_class'], $attribute, $this->getFactoryOptions($context));
try {
$attributeValue = $this->propertyAccessor->getValue($object, $attribute);
} catch (NoSuchPropertyException $e) {
if (null === $propertyMetadata->isChildInherited()) {
throw $e;
}
$attributeValue = null;
}
$type = $propertyMetadata->getType();
if ((is_array($attributeValue) || $attributeValue instanceof \Traversable) && $type && $type->isCollection() && ($collectionValueType = $type->getCollectionValueType()) && ($className = $collectionValueType->getClassName()) && $this->resourceClassResolver->isResourceClass($className)) {
$value = [];
foreach ($attributeValue as $index => $obj) {
$value[$index] = $this->normalizeRelation($propertyMetadata, $obj, $className, $format, $context);
}
return $value;
}
if ($attributeValue && $type && ($className = $type->getClassName()) && $this->resourceClassResolver->isResourceClass($className)) {
return $this->normalizeRelation($propertyMetadata, $attributeValue, $className, $format, $context);
}
return $this->serializer->normalize($attributeValue, $format, $context);
}