JSMSerialier 忽略了一些属性

JSMSerialier ignoring some properties

我正在尝试将 json 字符串反序列化为要与学说一起使用的实体。由于某种原因,我的一些属性被忽略了。

AppBundle\Entity\BoardSong.php

<?php

namespace AppBundle\Entity;

/**
 * BoardSound
 */
class BoardSound
{
    /**
     * @var integer
     */
    private $id;

    /**
     * @var Board
     */
    private $board;

    /**
     * @var File
     */
    private $file;

    /**
     * @var string
     */
    private $name;

    /**
     * @var int
     */
    private $startTime;

    /**
     * @var int
     */
    private $endTime;

    /**
     * @var string
     */
    private $backgroundColor;

    /**
     * @var string
     */
    private $borderColor;

    /**
     * @var string
     */
    private $textColor;

    /**
     * @var int
     */
    private $displayOrder;

    /**
     * @var string
     */
    private $note;

    /**
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * @param int $id
     * @return BoardSound
     */
    public function setId($id)
    {
        $this->id = $id;
        return $this;
    }

    /**
     * @return Board
     */
    public function getBoard()
    {
        return $this->board;
    }

    /**
     * @param Board $board
     * @return BoardSound
     */
    public function setBoard($board)
    {
        $this->board = $board;
        return $this;
    }

    /**
     * @return File
     */
    public function getFile()
    {
        return $this->file;
    }

    /**
     * @param File $file
     * @return BoardSound
     */
    public function setFile($file)
    {
        $this->file = $file;
        return $this;
    }

    /**
     * @return string
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * @param string $name
     * @return BoardSound
     */
    public function setName($name)
    {
        $this->name = $name;
        return $this;
    }

    /**
     * @return int
     */
    public function getStartTime()
    {
        return $this->startTime;
    }

    /**
     * @param int $startTime
     * @return BoardSound
     */
    public function setStartTime($startTime)
    {
        $this->startTime = $startTime;
        return $this;
    }

    /**
     * @return int
     */
    public function getEndTime()
    {
        return $this->endTime;
    }

    /**
     * @param int $endTime
     * @return BoardSound
     */
    public function setEndTime($endTime)
    {
        $this->endTime = $endTime;
        return $this;
    }

    /**
     * @return string
     */
    public function getBackgroundColor()
    {
        return $this->backgroundColor;
    }

    /**
     * @param string $backgroundColor
     * @return BoardSound
     */
    public function setBackgroundColor($backgroundColor)
    {
        $this->backgroundColor = $backgroundColor;
        return $this;
    }

    /**
     * @return string
     */
    public function getBorderColor()
    {
        return $this->borderColor;
    }

    /**
     * @param string $borderColor
     * @return BoardSound
     */
    public function setBorderColor($borderColor)
    {
        $this->borderColor = $borderColor;
        return $this;
    }

    /**
     * @return string
     */
    public function getTextColor()
    {
        return $this->textColor;
    }

    /**
     * @param string $textColor
     * @return BoardSound
     */
    public function setTextColor($textColor)
    {
        $this->textColor = $textColor;
        return $this;
    }

    /**
     * @return int
     */
    public function getDisplayOrder()
    {
        return $this->displayOrder;
    }

    /**
     * @param int $displayOrder
     * @return BoardSound
     */
    public function setDisplayOrder($displayOrder)
    {
        $this->displayOrder = $displayOrder;
        return $this;
    }

    /**
     * @return string
     */
    public function getNote()
    {
        return $this->note;
    }

    /**
     * @param string $note
     * @return BoardSound
     */
    public function setNote($note)
    {
        $this->note = $note;
        return $this;
    }
}

AppBundle\Resources\config\serializer\Entity.BoardSound.yml

AppBundle\Entity\BoardSound:
  properties:
    id:
      type: integer
      groups: [rpc]
    name:
      type: string
      groups: [rpc]
    file:
      type: AppBundle\Entity\File
      groups: [rpc]
    board:
      type: AppBundle\Entity\Board
      groups: [rpc]
    note:
      type: string
      groups: [rpc]
    backgroundColor:
      type: string
      groups: [rpc]
    borderColor:
      type: string
      groups: [rpc]
    textColor:
      type: string
      groups: [rpc]

我正在将此 json 传递给序列化程序:

{
    "file": {
        "id": "1"
    },
    "name": "Some Name",
    "note": "asdfasdfasdfasdf",
    "backgroundColor": "#ffffff",
    "boarderColor": "#000000",
    "textColor": "#000000",
    "board": {
        "id": 1
    }
}

并这样称呼它:

$serializer->deserialize($jsonString,'AppBundle\Entity\BoardSound', 'json');

出于某种原因,唯一受尊重的属性是板、文件、名称和注释。由于某种原因,所有其他字段都被忽略了。如有任何意见,我们将不胜感激。

@SerializedName

可以在 属性 上定义此注释以定义 属性 的序列化名称。如果未定义,属性 将从 camel-case 转换为带下划线的 lower-cased 名称,例如驼峰式 -> camel_case.

您可以阅读此处了解更多信息:http://jmsyst.com/libs/serializer/master/reference/annotations