I have an xml like this :
<screen>
<text id="qs65d4"></text>
<image id="xcq789"></image>
<text id="9s8xdf7"></text>
<button id="q6sd47"></button>
</screen>
I need to deserialize it and get an array of "screenobjects" here is what I tried :
class Screen {
/**
* @Type("array<string, MyBundle\Entity\ScreenObject>")
* @XmlList(entry = "*")
*/
protected $objects;
}
And my ScreenObject class
/**
* @Discriminator(field = "type", map = {
* "text": "MyBundle\Entity\ScreenObjects\Text",
* "image": "MyBundle\Entity\ScreenObjects\Image",
* "button": "MyBundle\Entity\ScreenObjects\Button"
* })
*/
class ScreenObject {
/**
* @Type("string")
*/
protected $id;
}
class Text extends ScreenObject{
/**
* @Type("string")
* @XmlAttribute
*/
protected $id;
public function getType() {
return 'text';
}
}
...
I know the wildcard @XmlList(entry = "")* is a bit hazardous, but I can't find my solution in the JMS documentation.
Thank for your help.
No comments:
Post a Comment