JSMSerialier忽略了一些属性
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JSMSerialier忽略了一些属性相关的知识,希望对你有一定的参考价值。
我正在尝试将json字符串反序列化为要与doctrine一起使用的实体。出于某种原因,我的一些属性被忽略了。
的appbundle 实体 BoardSong.php
<?php
namespace AppBundleEntity;
/**
* 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
AppBundleEntityBoardSound:
properties:
id:
type: integer
groups: [rpc]
name:
type: string
groups: [rpc]
file:
type: AppBundleEntityFile
groups: [rpc]
board:
type: AppBundleEntityBoard
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,'AppBundleEntityBoardSound', 'json');
由于某种原因,唯一被尊重的属性是板,文件,名称和注释。由于某种原因,所有其他字段都被忽略。任何输入将不胜感激。
答案
@SerializedName
可以在属性上定义此批注,以定义属性的序列化名称。如果未定义此属性,则该属性将从驼峰式转换为低级的强调名称,例如, camelCase - > camel_case。
您可以在这里阅读更多信息:http://jmsyst.com/libs/serializer/master/reference/annotations
以上是关于JSMSerialier忽略了一些属性的主要内容,如果未能解决你的问题,请参考以下文章