Using SerializedPath for arrays throws when deserializing XML with no children #58898
Replies: 2 comments
-
Hi @stefanfisk. I too have just started using this library and came across the same problem which left me stumped for a long time! The issue is when you are using the SerializedPath on something that can have 0+ entries. There are two 'problems' with the code above
To fix step one I created my own normalizer:
Then you need to create a Reservations class:
You may need to tweak a little as I have tried to match your classes from my implementation. I hope this helps π |
Beta Was this translation helpful? Give feedback.
-
Just stumbled across this too. Is there no way to do away with the additional container class? I'd rather have the empty string to just be an empty array and otherwise it being an array of the specified type. But the error happens before the denormalization π€ |
Beta Was this translation helpful? Give feedback.
-
I've just started using
symfony/serializer
and I'm using it outside of a Symfony project so I'm not sure if this is a bug or just an error on my part.I'm trying to deserialize some XML responses with nested element which I would like to not have to mirror in my class structure.
Here's an example:
And here's the classes I'm using:
Everything works great as long as
<reservations>
has children. If it is empty however, it throws:AFAICT the issue is that the normalized version of the XML becomes
['result' => ['reservations' => '']]
, which causesPropertyAccessor
to choke because it expects an array.Am I doing something wrong or is this a bug/known limitation?
Here's how I configure my serializer:
Beta Was this translation helpful? Give feedback.
All reactions