JMSSerializerBundle AccessorOrder自定义被忽略

时间:2015-09-30 00:48:54

标签: symfony jmsserializerbundle

我正在尝试使用JMSSerializerBundle注释来命令序列化输出数据。我明白了:

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": "federico.balderas@foograde.com",
    "country_code": "MX",
    "line2": "Col. Alameda"
}

知道我做错了什么?

1 个答案:

答案 0 :(得分:0)

似乎问题是CocoaRestCliente响应,Postman的响应是正确的。