private function denormalizeRelation(string $attributeName, PropertyMetadata $propertyMetadata, string $className, $value, string $format = null, array $context)
{
if (is_string($value)) {
try {
return $this->iriConverter->getItemFromIri($value, $context + ['fetch_data' => false]);
} catch (InvalidArgumentException $e) {
// Give a chance to other normalizers (e.g.: DateTimeNormalizer)
}
}
if (!$this->resourceClassResolver->isResourceClass($className) || $propertyMetadata->isWritableLink()) {
return $this->serializer->denormalize($value, $className, $format, $this->createRelationSerializationContext($className, $context));
}
if (!is_array($value)) {
throw new InvalidArgumentException(sprintf('Expected IRI or nested document for attribute "%s", "%s" given.', $attributeName, gettype($value)));
}
throw new InvalidArgumentException(sprintf('Nested documents for attribute "%s" are not allowed. Use IRIs instead.', $attributeName));
}