我正在尝试对以下XML进行反序列化:
<?xml version="1.0" encoding="utf-8"?>
<customers>
<customer>
<name>..</name>
<address>..</address>
<email>..</email>
<website>..</website>
</customer>
<customer>
...
</customer>
<customers>
我创建了以下实体:
use JMS'Serializer'Annotation as JMS;
class customers
{
public function __construct()
{
$this->customers = new ArrayCollection();
}
/**
* @JMS'Type("ArrayCollection<MyBundle'Entity'customer>")
* @JMS'XmlList(entry="customer")
*/
public $customers;
}
这是第二个实体:
use JMS'Serializer'Annotation as JMS;
class customer
{
/**
* @JMS'Type("string")
*/
public $name;
/**
* @JMS'Type("string")
*/
public $address;
/**
* @JMS'Type("string")
*/
public $email;
/**
* @JMS'Type("string")
*/
public $website;
}
然后在控制器中使用以下代码进行序列化:
$serializer = $this->get('jms_serializer');
$customers = $serializer->deserialize($inputStr, 'MyBundle'Entity'customers', 'xml');
只有对象一直为空?
尝试在客户类中更改注释为@JMS'XmlList(inline=true, entry="customer")