-
-
Notifications
You must be signed in to change notification settings - Fork 68
Description
I've been trying to debug the deserialization from a database of a vector object. While stepping through a unit test, I noticed that the property of another entity typed as a json_document column in the test was being treated as an array of objects. The requested type inside the Serializer is of App\MyDTO[], but the #type key is set to App\MyDTO in the database. Still, it is somehow being deserialized properly as a single object, while each element in my vector object's array is being treated as a vector object and failing.
I tracked down the appended [] to line 82 in the SerializerTrait
(not sure why the embedded snippet won't render)
The extra call to $this->denormalize on 82 supplies $data back to itself, but the #type key has been unset. So in that recursive denormalize call, it skips down to the is_iterable check, which evaluates to true because $data is an array. It then appends [] to the $type and delegates to the Symfony Serializer. It, in turn, delegates to the ArrayDenormalizer because [] has been appended.
I'm not sure why the data at times comes back fine as a single object and others do not.
I think removing line 82 altogether would solve the issue - it seems like parent::denormalize would be all that is needed to correctly return the denormalized data. As a test, I commented out 82 in my project, and the deserialization process actually works now for my vector type while also making less calls to other normalizers.