2015-09-30 38 views
0

我试图使用JMSSerializerBundle注释来序列化输出数据。我得到这个:JMSSerializerBundle AccessorOrder自定义忽略

use JMS\Serializer\Annotation\AccessorOrder; 

/** 
* @ORM\Entity(repositoryClass="AppBundle\Entity\CustomerRepository") 
* @ExclusionPolicy("all") 
* @AccessorOrder("custom", custom = {"custom_id", "company_name", "first_name", "last_name", "email", "phone_number", 
*       "line1", "line2", "line3", "city", "state", "postal_code", "country_code", "created_at"}) 
*/ 

/** 
* @ORM\Entity(repositoryClass="AppBundle\Entity\CustomerRepository") 
* @ExclusionPolicy("all") 
* @AccessorOrder("custom", custom = {"custom_id", "company_name", "first_name", "last_name", "email", "phone_number", 
*       "line1", "line2", "line3", "city", "state", "postal_code", "country_code", "created_at"}) 
*/ 
class Customer { 

    /** 
    * @var string 
    * @Expose 
    */ 
    private $first_name; 

    /** 
    * @var string 
    * @Expose 
    */ 
    private $last_name; 

    /** 
    * @var string 
    * @Expose 
    */ 
    private $email; 

    /** 
    * @var string 
    * @Expose 
    */ 
    private $phone_number; 

    /** 
    * @var string 
    * @Expose 
    */ 
    private $company_name; 

    /** 
    * @var string 
    * @Expose 
    */ 
    private $line1; 

    /** 
    * @var string 
    * @Expose 
    */ 
    private $line2; 

    /** 
    * @var string 
    * @Expose 
    */ 
    private $line3; 

    /** 
    * @var string 
    * @Expose 
    */ 
    private $city; 

    /** 
    * @var string 
    * @Expose 
    */ 
    private $state; 

    /** 
    * @var string 
    * @Expose 
    */ 
    private $postal_code; 

    /** 
    * @var string 
    * @Expose 
    */ 
    private $country_code; 

    /** 
    * @var \DateTime 
    * @Expose 
    */ 
    private $created_at; 

    /** 
    * @var string 
    * @Expose 
    * @SerializedName("id") 
    */ 
    private $customer_id; 
} 

,当我提出的要求,我得到这个:

{ 
    "id": "edf007d651855ab64f9c", 
    "state": "Guanajuato", 
    "created_at": "2015-09-17T12:42:21-0500", 
    "company_name": "Foograde", 
    "line1": "Gral. Ortega #223D", 
    "first_name": "Federico", 
    "city": "Celaya", 
    "postal_code": "38010", 
    "last_name": "Mata", 
    "email": "[email protected]", 
    "country_code": "MX", 
    "line2": "Col. Alameda" 
} 

什么我做错了任何想法?

+1

我想知道为什么你已经定义了两次注释? – tftd

+0

输入错误,当我发布的问题:P –

回答

0

看来问题是CocoaRestCliente响应,邮递员的反应是正确的。