2016-11-08 5 views
0
私は、次のXML deserialiseしようとしている

はDeserialiseのXML、取得空opbject

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; 
} 

これが第二の実体である:私は、次のエンティティをした

<?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 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")に変更してください。