JMS Serializer XmlList annotation



How to define cdata and namespace for @XmlList elements?


For example if I need to modify BlogPost from the example http://ift.tt/1uiXccL to have multiple authors:



use JMS\Serializer\Annotation as JMS;

/**
* @JMS\XmlNamespace(uri="http://ift.tt/14WYjKC")
* @JMS\XmlNamespace(uri="http://ift.tt/r5ut6F", prefix="atom")
* @JMS\XmlRoot("blog-post")
*/
class BlogPost
{
/**
* @JMS\Type("ArrayCollection<JMS\Serializer\Tests\Fixtures\Author>")
* @JMS\XmlList(inline = true, entry="author")
*
* replaced XmlElement(namespace="http://ift.tt/r5ut6F") with XmlList
*/
private $author;
}


with serialized xml similar to:



<?xml version="1.0" encoding="UTF-8"?>
<blog-post xmlns="http://ift.tt/14WYjKC" xmlns:atom="http://ift.tt/r5ut6F">
<atom:author>
<full_name>Foo Bar></full_name>
</atom:author>
<atom:author>
<full_name>Baz Qux></full_name>
</atom:author>
</blog>


For single @XmlElement both cdata and namespace work just fine, but @XmlList and @XmlCollection have nothing like this.


Any clue where should I put annotation for elements in the list?


No comments:

Post a Comment