-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Serializer][Bug] deserialize into pre-existing objects in properties #31208
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
Comments
BTW I've hot-patched this just to test if it will work like this and it does: class AbstractObjectNormalizer
{
// ...
protected function createChildContext(array $parentContext, $attribute): array
{
$context = parent::createChildContext($parentContext, $attribute);
if (isset($parentContext[self::OBJECT_TO_POPULATE])) {
$attribute = $this->getAttributeValue($parentContext[self::OBJECT_TO_POPULATE], $attribute);
if (is_object($attribute)) {
$context[self::OBJECT_TO_POPULATE] = $attribute;
}
}
return $context;
}
} I'm sure @dunglas will have a better idea how to fix this. |
Maybe could we reuse some logic of |
Hey, thanks for your report! |
The issue was not tagged from a PR fixing it so I guess it's still relevant. |
Hey, thanks for your report! |
/carsonbot freeze ? |
@dkarlovi PR welcome if you would like to give it a try |
Hey, thanks for your report! |
Just a quick reminder to make a comment on this. If I don't hear anything I'll close this. |
I'm doing science and I'm still alive. |
Hey, thanks for your report! |
Friendly ping? Should this still be open? I will close if I don't hear anything. |
Hey, I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen! |
Symfony version(s) affected: 4.2.3
Description
Assuming I have classes like this:
and instance like
When deserializing:
I'd expect the pre-existing
Inner
instance to be used, but a new one is created.How to reproduce
https://github.com/dkarlovi/reproducer-symfony-31208
Possible Solution
Pre-populate
OBJECT_TO_POPULATE
with the pre-existing object if not-null?The text was updated successfully, but these errors were encountered: