私はAcme\Bundle\Entity\Article
と1対多の関係を持つエンティティAcme\Bundle\Entity\Author
を持っています。両方のエンティティに対して2つのJMSシリアライザイベントサブスクライバがあります。JMSシリアライザイベント加入者フィルタアウトプロキシクラス
サブスクライバーAcme\Bundle\Entity\Author
;
acm.author_serialization_listener:
class: Acm\Bundle\Listener\AuthorSerializationListener
tags:
- { name: jms_serializer.event_subscriber }
class AuthorSerializationListener implements EventSubscriberInterface
{
/**
* @inheritdoc
*/
public static function getSubscribedEvents()
{
return array(
array('event' => 'serializer.pre_serialize', 'class' => 'Acme\Bundle\Entity\Author' 'method' => 'onPreSerialize'),
);
}
public function onPreSerialize(PreSerializeEvent $event)
{
if($event->getObject() instanceof Author) {
return;
}
}
}
Acme\Bundle\Entity\Article
ためのサブスクライバ。
acm.article_serialization_listener:
class: Acm\Bundle\Listener\ArticleSerializationListener
tags:
- { name: jms_serializer.event_subscriber }
class ArticleSerializationListener implements EventSubscriberInterface
{
/**
* @inheritdoc
*/
public static function getSubscribedEvents()
{
return array(
array('event' => 'serializer.pre_serialize', 'class' => 'Acme\Bundle\Entity\Article' 'method' => 'onPreSerialize'),
);
}
public function onPreSerialize(PreSerializeEvent $event)
{
if($event->getObject() instanceof Article) {
return;
}
}
}
ではなくプロキシ\ __ CG __ \アクメ\バンドル\エンティティ\条を注入ArticleSerializationListener
加入者クラスでArticle
■関連と一緒にAuthor
をシリアライズするときに問題がonPreSerialize
関数で発生Acme \ Bundle \ Entity \ Article関連エンティティを除外するようになるエンティティ。私が間違ってやっていることがあるのですか、これには回避策がありますか?
シリアライザは、getSubscribedEvents自体の 'class'フィルタからシリアライザに必要なエンティティを取得しないので、あなたのsoltionはまったく機能しません。私は私の質問をあなたのためにもっと明確に編集しました。 構文修正をありがとう! – ssrp
あなたはその問題についてより具体的になりますか? – stepotronic