使用JMS Serializer反序列化XML,获得空的opbject

时间:2016-11-08 21:19:02

标签: php xml symfony jms-serializer

我正在尝试反序列化以下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');

只有对象不断变空?

1 个答案:

答案 0 :(得分:0)

尝试在类Customer中将注释更改为shutdown /h /t 18000