-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
nested XML attributes not deserializing #51827
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
I created a small project that shows this problem: git clone [email protected]:tacman/xml-serializer-bug-demo.git && cd xml-serializer-bug-demo && composer install && bin/console app:bug
bin/console server:start
# the home page dumps some things, in case the serializer profile provides some clues. |
Hi there! Thank you for reporting the issue. I tried some config on the reproducer (thank you @tacman), and in fact, passing the $product = (new Product())
->setDescription("Wool sweater")
->addProperty((new Property())->setName('color')->setValue('blue'))
->addProperty((new Property())->setName('size')->setValue('small'))
;
$context = [
'xml_root_node_name' => 'product',
'groups' => ['xml'],
'xml_standalone' => false,
'xml_format_output' => true,
];
$xml = $this->serializer->serialize($product, 'xml', $context);
$context = [
'xml_root_node_name' => 'product',
'groups' => ['xml']
];
$product2 = $this->serializer->deserialize($xml, Product::class, 'xml', $context);
|
Indeed, you need to have a matching group here. According to the So you can either provide the |
Oh, now it makes sense! Deserializing needs a $context too, with the group. Thanks very much for solving this! |
Symfony version(s) affected
all
Description
When serializing an entity with related entities, and those entities are configured to have attributes, deserializing does not work.
This XML can be generated from the entity but not deserialized.
How to reproduce
This works as expected, the $xml string is now:
But deserializing that XML doesn't work:
The Serializer is configured so that Product description and Property name are attributes.
The entities are simple and were created with bin/console make:entity. Setters and getters are generated and so not shown.
Possible Solution
I'm guessing that the issue is that the serialization.yaml file isn't configured correctly, but since serializing works, I'm not sure what the error is.
Additional Context
I thought this might be related to #51594 or #51701, but the issue persists.
The text was updated successfully, but these errors were encountered: