Symfony 2.8、FOSRestBundle、および JMSSerializerBundle を使用しています。
問題
entity の特定のグループ (次の例では「api」グループ) をシリアル化すると、エンティティのDiscriminator フィールドtype
がシリアル化されたモデルに表示されません。Document
Citizen
教義の実体
書類:
namespace MyBundle\Entity;
use JMS\Serializer\Annotation as JMS;
…
/**
* @JMS\Discriminator(field = "type", map = {
* "doc1" = "MyBundle\Entity\Document1",
* "doc2" = "MyBundle\Entity\Document2"
* })
*/
class Document
…
市民:
class Citizen
{
…
/**
* @var ArrayCollection
*
* @ORM\OneToMany(
* targetEntity="MyBundle\Entity\Document",
* cascade={ "PERSIST", "REMOVE" },
* orphanRemoval=true,
* mappedBy="citizen"
* )
*
* @JMS\Groups({"api"})
*/
private $documents;
…
私が得るもの
{
…
"documents": [
{
"number": "000000",
"date": "01.01.1970",
"serial": "0000",
"place": ""
}
],
…
}
必要なもの
{
…
"documents": [
{
"type": "doc1",
"number": "000000",
"date": "01.01.1970",
"serial": "0000",
"place": ""
}
],
…
}
特定のシリアル化グループを削除するとtype
、シリアル化された出力にフィールドが存在します。
前もって感謝します