Property with the SeralizedPath-Attribute is not properly converted by Serializer #49225
-
Hi! I have the problem that a DTO with My goal is to create an XML like this one: <?xml version="1.0" encoding="UTF-8"?>
<root>
<methods>
<include code="Method A"/>
<include code="Method B"/>
</methods>
</root> For example with such a class: class TestClass
{
#[SerializedPath('[methods][include][@code]')]
public array $methods = ['Method A', 'Method B'];
}
// ...
$this->serializer->serialize(new TestClass(), 'xml'); But I just get always the same issue: {
"title": "An error occurred",
"detail": "The element you are trying to set is already populated: \"[methods][include][@code]\".",
"trace": [
{
"file": "/srv/api/vendor/symfony/serializer/Normalizer/AbstractObjectNormalizer.php",
"line": 655
}
]
} I already looked at the documentation for the Perhaps one approaches the matter in a completely different way. I just want to avoid all the nested DTOs with SerializedName attributes. If anyone can help, I would be very grateful! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Sounds like this is related to #49494. I've tested your code with the fix from the branch and it seems to work when changing |
Beta Was this translation helpful? Give feedback.
Sounds like this is related to #49494. I've tested your code with the fix from the branch and it seems to work when changing
$methods
to a string (assigning an array to a XML attribute with the@
prefix throws an error).