-
-
Notifications
You must be signed in to change notification settings - Fork 895
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exception when using Ramsey/Uuid ^4.0 #3473
Comments
You may not need this normalizer after all, could you trying removing it to see if everything works as expected? |
All my GET-Item Operations are working without the Normalizer. My POST test is failing now
|
My guess is that the denormalizer can't use the Uuid class as-is. Would you be able to add a denormalizer for the Uuid type (see https://symfony.com/doc/current/serializer/custom_normalizer.html#creating-a-new-normalizer) to see if it fixes it. |
It works if i adjust the UuidNormalizer with the check i suggested in "Possible solution".
to return ($data instanceof UuidInterface) ? $data : Uuid::fromString($data);
That fixes the problem and should not impact older versions of ramsey. @soyuka Im not sure what denormalizer i should add. The existing one already supports the UuidInterface. Can you give me a hint ? |
There is a difference between the Identifier normalizer and the denormalizer I suggested. In fact what bother's me is that we already have:
The code should not go through the |
Fix ramsey uuid denormalization #3473
API Platform version(s) affected: x.y.z
Description
After updating to Ramsey/Uuid ^4.0 i get an exception when querying an item with identifier. For example api/books/3fa85f64-5717-4562-b3fc-2c963f66afa6
The exception:
Argument 1 passed to Ramsey\Uuid\Uuid::fromString() must be of the type string, object given, called in ..\vendor\api-platform\core\src\Bridge\RamseyUuid\Identifier\Normalizer\UuidNormalizer.php on line 35
$data contains an Uuid object instead of an string , the Uuid is my identifier.
It works fine with Ramsey/Uuid ^3.9 !
Possible Solution
Add a check if $data is a string or an instance of UuidInterface in the UuidNormalizer
The text was updated successfully, but these errors were encountered: