2016-11-08 23 views
0

我想deserialise以下XML:Deserialise XML與JMS串行,漸漸空虛opbject

<?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

嘗試改變,在類客戶中,註釋爲@JMS\XmlList(inline=true, entry="customer")