JMSSerializerBundle icon indicating copy to clipboard operation
JMSSerializerBundle copied to clipboard

Enhancement: make XmlList available for classes

Open marco-santamaria opened this issue 11 years ago • 2 comments

Currently you can use XmlList only for properties and methods, therefore if you want to list all posts of a blog you can't have

<result>
    <post>
        <title><![CDATA[Foo]]></title>
        <body><![CDATA[Text for Foo]]></body>
    </post>
    <post>
        <title><![CDATA[Bar]]></title>
        <body><![CDATA[Text for Bar]]></body>
    </post>
</result>

but you get

<result>
    <entry>
        <title><![CDATA[Foo]]></title>
        <body><![CDATA[Text for Foo]]></body>
    </entry>
    <entry>
        <title><![CDATA[Bar]]></title>
        <body><![CDATA[Text for Bar]]></body>
    </entry>
</result>

The entry name seems only customizable for xml collections in a property. See the visitArray() method in XmlSerializationVisitor.php.

marco-santamaria avatar Oct 30 '12 11:10 marco-santamaria

What would you gain from it? XMLList only seems useful in the context of serializing a list of items, not the entirety of an object.

wjaspers avatar Feb 27 '13 03:02 wjaspers

@marco-santamaria So I guess you are serializing an array of blog post objects. $array = array(new BlogPost(), new BlogPost()); which makes it impossible to specify the xml name for each entry. I agree the solution to it would be add a new annotation like XmlEntry("post") which specifies the entry name of the class in an array. Also I wonder what XmlRoot stands for if used on subchilds? What if there are multiple XmlRoots given for a tree of objects? Maybe we can also use XmlRoot to specifiy entry names on a class level for childs. Thus not needed XmlEntry.

Tobion avatar Nov 30 '13 21:11 Tobion