-
-
Notifications
You must be signed in to change notification settings - Fork 67
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
Redundant denormalize call in SerializerTrait #127
Comments
I forked it, made the change, and ran the test suite. It seems removing it breaks the
|
I had a moment of realization - the class I'm trying to serialize implements the |
Well, this thing brokes my wishes to use that library, so sad. |
@Arkemlar you can create a custom normalizer for your iterable type class VectorNormalizer implements NormalizerInterface
{
function supportsNormalization($object)
{
return $object instance of Vector;
}
function normalize($object)
{
return $object->getArray();
}
} You don't need a custom denormalizer so long as |
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 toApp\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 SerializerTraithttps://github.com/dunglas/doctrine-json-odm/blob/89b01483c4f6e7a5e25fc2ea18b2fe46574617ae/src/SerializerTrait.php#L70C5-L94C6
(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 recursivedenormalize
call, it skips down to theis_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.The text was updated successfully, but these errors were encountered: