我正在尝试反序列化以下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');
只有对象不断变空?
答案 0 :(得分:0)
尝试在类Customer中将注释更改为shutdown /h /t 18000