我正在尝试将json字符串反序列化为要与doctrine一起使用的实体。出于某种原因,我的一些属性被忽略了。
的appbundle \实体\ 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 \资源\ CONFIG \串行\ 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
可以在属性上定义此批注,以定义属性的序列化名称。如果未定义此属性,则该属性将从驼峰式转换为低级的强调名称,例如, camelCase - > camel_case。
您可以在这里阅读更多信息:http://jmsyst.com/libs/serializer/master/reference/annotations