API Platform version
4.3.9 (also reproduces on 4.3.8). Last working version: 4.3.7.
PHP version
8.4
Symfony version
6.4 LTS — symfony/serializer 6.4.37 (full Symfony stack on 6.4.x).
Description
After upgrading api-platform from 4.3.7 → 4.3.9 (no other dependency changed — symfony/serializer. stayed at 6.4.37), container/cache warmup fails with:
TypeError - Exception:
`Symfony\Component\Serializer\Mapping\Loader\AttributeLoader::__construct(): Argument #1 ($reader) must be of type ?Doctrine\Common\Annotations\Reader, true given, called in .../getSerializer_Mapping_CacheWarmerService.php on line 21 in vendor/symfony/serializer/Mapping/Loader/AttributeLoader.php (49)
#0 .../getSerializer_Mapping_CacheWarmerService.php(21): Symfony\Component\Serializer\Mapping\Loader\AttributeLoader->__construct()
#1 .../Container.php(...): getSerializer_Mapping_CacheWarmerService::do()
#2 .../getCacheWarmerService.php(25): ...->load()
#3 vendor/symfony/http-kernel/CacheWarmer/CacheWarmerAggregate.php(99): ...
#4 vendor/symfony/http-kernel/Kernel.php(565): CacheWarmerAggregate->warmUp()
#5 vendor/symfony/http-kernel/Kernel.php(783): Kernel->initializeContainer()`
On symfony/serializer 6.4, AttributeLoader::__construct() takes ?Doctrine\Common\Annotations\Reader $reader as its first argument, but the compiled serializer-mapping loader service is now constructed with a boolean true as that argument, which fails the type check. Nothing in our application configures the serializer mapping loader — the service is registered by the framework + api-platform bundle, and the only thing that changed was the api-platform version.
Why this looks like a regression on api-platform's side
api-platform/serializer 4.3.9 still declares "symfony/serializer": "^6.4.37 || ^7.4.9 || ^8.0.9", i.e. Symfony 6.4.37 is an officially supported target.
- The exact same
symfony/serializer 6.4.37 works fine with api-platform 4.3.7.
- Only the api-platform packages moved (4.3.7 → 4.3.9); no Symfony/serializer change.
This suggests something in the 4.3.8/4.3.9 serializer/enable_attributes wiring now assumes the Symfony 7.x AttributeLoader signature and passes a bool where Symfony 6.4 expects ?Reader.
Suspected cause
Changes around serializer mapping / enable_attributes in the 4.3.7…4.3.9 range, in particular:
Downgrading the whole api-platform/* family back to 4.3.7 resolves it.
Possible solution
When symfony/serializer is on the 6.4 branch, construct the serializer mapping AttributeLoader with the 6.4-compatible signature (?Reader $reader) instead of passing the enableAttributes boolean positionally, or guard the wiring by installed serializer version.
API Platform version
4.3.9 (also reproduces on 4.3.8). Last working version: 4.3.7.
PHP version
8.4
Symfony version
6.4 LTS —
symfony/serializer6.4.37 (full Symfony stack on 6.4.x).Description
After upgrading api-platform from 4.3.7 → 4.3.9 (no other dependency changed —
symfony/serializer. stayed at6.4.37), container/cache warmup fails with:TypeError - Exception:
`Symfony\Component\Serializer\Mapping\Loader\AttributeLoader::__construct(): Argument #1 ($reader) must be of type ?Doctrine\Common\Annotations\Reader, true given, called in .../getSerializer_Mapping_CacheWarmerService.php on line 21 in vendor/symfony/serializer/Mapping/Loader/AttributeLoader.php (49)
#0 .../getSerializer_Mapping_CacheWarmerService.php(21): Symfony\Component\Serializer\Mapping\Loader\AttributeLoader->__construct()
#1 .../Container.php(...): getSerializer_Mapping_CacheWarmerService::do()
#2 .../getCacheWarmerService.php(25): ...->load()
#3 vendor/symfony/http-kernel/CacheWarmer/CacheWarmerAggregate.php(99): ...
#4 vendor/symfony/http-kernel/Kernel.php(565): CacheWarmerAggregate->warmUp()
#5 vendor/symfony/http-kernel/Kernel.php(783): Kernel->initializeContainer()`
On
symfony/serializer6.4,AttributeLoader::__construct()takes?Doctrine\Common\Annotations\Reader $readeras its first argument, but the compiled serializer-mapping loader service is now constructed with a booleantrueas that argument, which fails the type check. Nothing in our application configures the serializer mapping loader — the service is registered by the framework + api-platform bundle, and the only thing that changed was the api-platform version.Why this looks like a regression on api-platform's side
api-platform/serializer4.3.9 still declares"symfony/serializer": "^6.4.37 || ^7.4.9 || ^8.0.9", i.e. Symfony 6.4.37 is an officially supported target.symfony/serializer6.4.37 works fine with api-platform 4.3.7.This suggests something in the 4.3.8/4.3.9 serializer/
enable_attributeswiring now assumes the Symfony 7.xAttributeLoadersignature and passes a bool where Symfony 6.4 expects?Reader.Suspected cause
Changes around serializer mapping /
enable_attributesin the 4.3.7…4.3.9 range, in particular:fix(symfony): keep error serialization mapping when enable_attributes is disabled(fix(symfony): keep error serialization mapping when enable_attributes is disabled #8231)fix(serializer): bump min serializer dep ...Downgrading the whole
api-platform/*family back to4.3.7resolves it.Possible solution
When
symfony/serializeris on the 6.4 branch, construct the serializer mappingAttributeLoaderwith the 6.4-compatible signature (?Reader $reader) instead of passing theenableAttributesboolean positionally, or guard the wiring by installed serializer version.