Repository navigation
Conversation
A property that declares a collection class, such as a Doctrine collection, was denormalized into a plain array. The item normalizer kept only the element class and asked the Serializer for "Foo[]", then the property accessor could not write that array into the collection. The declared container class is now passed to the Serializer, together with the element and key types in the "value_type" and "key_type" context entries. The core Serializer uses those entries to carry the element type of a collection, and the Doctrine bridge collection denormalizer builds the collection from them. The class is checked with class_exists, so older Symfony versions keep the "Foo[]" type. A container that is a plain array or iterable is not affected.
GromNaN
marked this pull request as draft
October 6, 2026 04:25
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A property that declares a collection class, such as
Doctrine\Common\Collections\Collection, was denormalized into a plain array. The item normalizer kept only the element class and asked the Serializer forFoo[], andPropertyAccessor::setValue()could not write that array into the collection, so the request failed with a 422.DenormalizerInterface::denormalize()only takes a string type, so the container class cannot be part of the type. The core Serializer carries the element type of a collection in thevalue_typeandkey_typecontext entries.AbstractItemNormalizernow reads the declared container class from the property type and passes it with those two entries, mirroringAbstractObjectNormalizer::getCollectionContainerClass().The test is
testDenormalizeCollectionWithAClassContainerinsrc/Serializer/Tests/AbstractItemNormalizerTest.php. It asserts the type and the context handed to the Serializer, and the value written back to the object.class_exists(CollectionDenormalizer::class)keeps the previous behavior on Symfony versions that do not ship the Doctrine collection denormalizer yet. That class is added in Symfony 8.2 (symfony/symfony#66144), and the api-platform constraintsymfony/doctrine-bridge: ^7.4 || ^8.0accepts it. The test covers both branches, so it runs on the current dependencies and on Symfony 8.2 without a change.A container that is a plain
arrayoriterablekeeps theFoo[]type.The resource-collection branch above (
denormalizeObjectCollection) has the same limitation when the elements are API resources. This pull request does not touch it.