Closed hnrch02 closed 2 years ago
Oh hey, people are using this library! :smile:
Unfortunately, I don't think what you're doing is possible directly. Serde doesn't know from the docblocks, only the attributes, and there's no way to document the type of the inner array. The deserializer will see the incoming array but have no idea that it's supposed to map it to something. Objects nested inside arrays are just not sufficiently self-describing.
Possible workarounds to try:
ObjectImporter
yourself and make a new one, and have it apply just to your Test
class. Then hard code whatever additional logic you can make work for that structure.Off hand, I suspect a custom importer is the most promising.
Hi, loving the library so far!
I'm struggling to properly deserialize dictionaries whose values are arrays of objects. This is where I'm at:
As the PHPDoc specifies, the
$notes
member of theTest
class is supposed to be a dictionary with string keys andNote
arrays as values.I managed to get it to work by introducing a
Notes
intermediary class, which I can then specify as thearrayType
like so:but this is not ideal, since it complicates the serialized output unnecessarily, and makes it harder to address the individual elements as I have to go through the
Notes
class. I also tried applying type maps, but I didn't get far with that either.So my question is: Can I do this in a better way? Maybe I'm missing an obvious solution here, so I would be grateful if someone could point me in the right direction.