JMS Serializer XmlList annotation

1.3k views Asked by At

How to define cdata and namespace for @XmlList elements?

For example if I need to modify BlogPost from the example http://jmsyst.com/libs/serializer/master/reference/annotations#xmlnamespace to have multiple authors:

use JMS\Serializer\Annotation as JMS;

/**
 * @JMS\XmlNamespace(uri="http://example.com/namespace")
 * @JMS\XmlNamespace(uri="http://www.w3.org/2005/Atom", 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://www.w3.org/2005/Atom") with XmlList
     */
    private $author;
}

with serialized xml similar to:

<?xml version="1.0" encoding="UTF-8"?>
<blog-post xmlns="http://example.com/namespace" xmlns:atom="http://www.w3.org/2005/Atom">
    <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?

0

There are 0 answers