-
-
Notifications
You must be signed in to change notification settings - Fork 356
[LiveComponent] Fix collections hydration with serializer #1583
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
[LiveComponent] Fix collections hydration with serializer #1583
Conversation
05959a5
to
ec70907
Compare
@@ -259,7 +259,9 @@ public function hydrateValue(mixed $value, LivePropMetadata $propMetadata, objec | |||
throw new \LogicException(sprintf('The "%s::%s" object should be hydrated with the Serializer, but no type could be guessed.', $parentObject::class, $propMetadata->getName())); | |||
} | |||
|
|||
return $this->serializer->denormalize($value, $propMetadata->getType(), 'json', $propMetadata->serializationContext()); | |||
$type = $propMetadata->collectionValueType() ? $propMetadata->collectionValueType()->getClassName().'[]' : $propMetadata->getType(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to also check for Type::BUILTIN_TYPE_OBJECT === $propMetadata->collectionValueType()->getBuiltinType()
like we do on line 267? Basically, what if this is typed as string[]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes absolutely, I missed those cases. Next commit fixes that, and also ensures the built-in collection type is scalar (if used). Otherwise the "not guessable type" exception is thrown
9a5d6cc
to
881c643
Compare
881c643
to
7a8bc4f
Compare
Thanks Nicolas! |
Oh i missed this one ! So cool 👏 |
Hello!
I encountered issues when trying to hydrate a
LiveProp
as a collection of objects, using the Symfony Serializer.Given
phpdocumentor/reflection-dockblock
is installed in the project, and I have the following component:Then I should be able to hydrate
$prop
as a collection ofMyDto
.However, the
LiveComponentHydrator
doesn't consider the collection type whenuseSerializerForHydration
is enabled, and tries to deserialize toarray
type, throwing the following exception:So here is a proposal to fix the issue.
Cheers!