Open tgaertner opened 1 year ago
Hi @tgaertner! This usage seems to be a bit hacky to override the property types on the Factory level and might impact performance & Could you provide more context what is a use case for you? May I will be better to help you with some better solution :)
Well this is some legacy code, I haven't written. The full function looks like this:
/**
* @param string $embeddedType
* @return string
*/
protected function getPagerType(string $embeddedType)
{
$type = [
'name' => 'array',
'params' => [
[
'name' => $embeddedType,
'params' => [],
],
],
];
// Overrides Configuration: Vendor.Package.Persistence.HATEOAS.Content.yml
/** @var PropertyMetadata $itemsMetadata */
$itemsMetadata = $this->serializer->getMetadataFactory()->getMetadataForClass(Content::class)->propertyMetadata['items'];
$itemsMetadata->setType($type);
return Pager::class;
}
This function is only called to override the type for embedded Objects to serialize.
Re-add getter for MetadataFactory in Serialzier to make it possible again to override metadata types like this: /* @var \JMS\Serializer\Metadata\PropertyMetadata $itemsMetadata / $itemsMetadata = $this->serializer->getMetadataFactory()->getMetadataForClass(Content::class)->propertyMetadata['items']; $itemsMetadata->setType($type);
Expected Result
Actual Result