我有这样的xml。
<projects>
<entry key="project"></entry>
<entry key="project"></entry>
<entry key="project"></entry>
</projects>
和实体
class Project
{
const ENCODING = 'UTF-8';
/**
* @var integer
*/
protected $id;
/**
* @var array(\ACme\ProjectBundle\Entity\Project)
* @JMS\Type("array<Acme\ProjectBundle\Entity\Project>")
* @JMS\XmlList(entry="projects")
*/
protected $projects;
}
我尝试使用JMS序列化程序对其进行反序列化:
return $this->serializer->deserialize($rawXml, 'array<Acme\ProjectBundle\Entity\Project>', 'xml');
但我仍然收到错误消息:
The array type must be specified either as "array<T>", or "array<K,V>".
答案 0 :(得分:0)
尝试使用:
ArrayCollection<Acme\ProjectBundle\Entity\Project>
答案 1 :(得分:0)
我认为它会以这种方式运作:
class Projects
{
/**
* @JMS\Type("array<Acme\ProjectBundle\Entity\Project>")
* @JMS\XmlList(entry="entry")
*/
protected $entries;
}
class Project
{
/**
* @JMS\Type("string")
* @JMS\XmlAttribute
*/
protected $key;
}