依存関係を持つエンティティをシリアライズおよびデシリアライズしたいのですが、抽象クラスに関係する要素をシリアライズできません。
階層 :
テスト --> クラスが抽象クラスであり、によって拡張されている複数のテストCalls
(Call
とTestCallExecuteQuery
同じ問題$conditions
)
Test.php :
/**
* @ORM\Entity(repositoryClass="Gedmo\Sortable\Entity\Repository\SortableRepository")
* @ORM\Table(name="cfa_test")
* @JMSSer\ExclusionPolicy("all")
*/
class Test
{
/**
* @ORM\OneToMany(targetEntity="TestCall", mappedBy="test", cascade={"all"}, orphanRemoval=true)
* @JMSSer\Expose
* @JMSSer\Groups({"export"})
* @JMSSer\Type("ArrayCollection<App\Bundle\CapFileAnalyzerBundle\Entity\TestCall>")
*/
protected $calls;
/**
* @ORM\OneToMany(targetEntity="TestCondition", mappedBy="test", cascade={"all"}, orphanRemoval=true)
* @JMSSer\Expose
* @JMSSer\Groups({"export"})
* @JMSSer\Type("ArrayCollection<App\Bundle\CapFileAnalyzerBundle\Entity\TestCondition>")
*/
protected $conditions;
TestCall.php :
/**
* @ORM\Entity
* @ORM\InheritanceType("SINGLE_TABLE")
* @ORM\Table(name="cfa_test_call")
* @ORM\DiscriminatorColumn(name="type", type="string")
* @ORM\DiscriminatorMap({
* "executeQuery" = "App\Bundle\CapFileAnalyzerBundle\Entity\TestCallExecuteQuery",
* "call" = "App\Bundle\CapFileAnalyzerBundle\Entity\TestCall"
* })
* @JMSSer\ExclusionPolicy("all")
* @JMSSer\Discriminator(field="serializedType", map={
* "executeQuery"="App\Bundle\CapFileAnalyzerBundle\Entity\TestCallExecuteQuery",
* "call" = "App\Bundle\CapFileAnalyzerBundle\Entity\TestCall"
* })
*/
abstract class TestCall
{
/**
* @JMSSer\Expose
* @JMSSer\Groups({"export"})
*/
protected $type = 'call';
/**
* @ORM\Id
* @ORM\Column(name="id", type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="Test", inversedBy="calls")
*/
protected $test;
/**
* @JMSSer\VirtualProperty()
* @JMSSer\SerializedName("serializedType")
*/
public function getDiscr()
{
return $this->type;
}
TestCallExecuteQuery.php :
/**
* @ORM\Entity
* @JMSSer\ExclusionPolicy("all")
*/
class TestCallExecuteQuery extends TestCall
{
protected $type = 'executeQuery';
/**
* @ORM\Column(name="`query`", type="text")
* @JMSSer\Expose
* @JMSSer\Groups({"export"})
*/
protected $query;
/**
* @ORM\Column(name="`return`", type="string", nullable=true)
* @JMSSer\Expose
* @JMSSer\Groups({"export"})
*/
protected $return;
だから私はインターネット上で見つけた指示に従いました:
@JMSSer\Expose
@JMSSer\ExclusionPolicy("all")
すべてのクラスでの注釈@JMSSer\Discriminator
TestCall
拡張クラスにマップするための抽象クラスの上の注釈(TestcallExecuteQuery
)
しかし..シリアル化すると、TestCallの型プロパティのみを取得しますが、で定義されたプロパティは取得しquery
ません:return
TestCallExecuteQuery
{"tests":[{"calls":[{"type":"executeQuery"},{"type":"executeQuery"}], ... }
一回手に入れたので可能性はあると思いますが、時計を戻しても再現できませんでした..
{"tests":[{"calls":[{"query":"SELECT * FROM table","return":"return_1"}], ... }
編集 :
わかりました私はおそらく得query
てreturn
、変更することでTest.php
:
/**
* @JMSSer\Type("ArrayCollection<App\Bundle\CapFileAnalyzerBundle\Entity\TestCall>")
*/
protected $calls;
に :
/**
* @JMSSer\Type("ArrayCollection<App\Bundle\CapFileAnalyzerBundle\Entity\TestCallExecuteQuery>")
*/
protected $calls;
私は何を間違っていますか?