JMSerializerbundle:反序列化具有不同名称的节点子节点

时间:2015-02-18 09:40:04

标签: php xml jmsserializerbundle

我有一个像这样的xml:

<screen>
    <text id="qs65d4"></text>
    <image id="xcq789"></image>
    <text id="9s8xdf7"></text>
    <button id="q6sd47"></button>
</screen>

我需要对其进行反序列化并获取一系列“screenobjects”,这是我尝试过的:

class Screen {
    /**
     * @Type("array<string, MyBundle\Entity\ScreenObject>")
     * @XmlList(entry = "*")
     */
    protected $objects;

}

我的ScreenObject类

/**
 * @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';
    }

}
...

我知道通配符 @XmlList(entry =“”)*有点危险,但我在JMS文档中找不到我的解决方案。

感谢您的帮助。

0 个答案:

没有答案