Replies: 1 comment
-
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Is it by design that ApiPlatform is meant to always pass Collections as array, e.g. when submitting to the POST Endpoint?
According to the code yes, but is this intended? https://github.com/api-platform/core/blob/master/src/Serializer/AbstractItemNormalizer.php#L397
To paraphrase the error I got:
Argument n passed to App\\Entity\\Product::__construct() must be an instance of App\\Collection\\PriceCollection, array given
- (it is passing me an array of Prices, but I need the Prices inside a PriceCollection)This wouldn't be a problem if I could use a custom Item Denormalizer to create the PriceCollection, but I cant with 2.4.2 anymore.
In 2.4.2 I never even see PriceCollection reach the "supportsDenormalization" method of my Normalizer.
As soon as I downgrade from 2.4.2 to 2.3.6 my custom Denormalizer "works" again.
With 2.3.6 the PriceCollection reaches the Normalizer and submitting to "POST" works.
Could be related to #2662 ? (not sure though)
I already tried #2679 but it didn't do anything in my case, unless I missed something.
In the simplified php code (I left out most Annotations, this is mostly to exemplify the way it is setup) below ApiPlatform always passes "array" to the Product Constructor while ProductCollection is expected.
Note
Product
andPrice
are Entities/ Resources. PriceCollection however is not (it's just a simple object to ensure only entities of TypePrice
are actually passed toProduct
)Beta Was this translation helpful? Give feedback.
All reactions