我有一个在Symfony2中开发的API但是当我向它发送请求时,响应返回204Mb只有40行...这是代码:
$em = $this->getDoctrine()->getManager();
$themes = $em->getRepository("KlickpagesAdminBundle:Theme")->findAll();
return $themes;
我使用FOSRestBundle来序列化并返回json。
我如何解决这个问题?
答案 0 :(得分:2)
Aa @Cerad说这很像是因为与其他实体的关系以及圈内的延迟加载
对于快速测试,排除序列中的所有字段,除了少数标量字段,如下:
setListAdapter
重要的部分是排除策略并揭露反对。
如果这会有所帮助,您肯定会对注释进行循环序列化,而正确的解决方案是定义序列化组,如下所示:
java.lang.ClassCastException: android.support.v4.view.ViewPager$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
然后,您可以定义应该在控制器上以编程方式序列化响应的组。
use JMS\Serializer\Annotation\Expose;
use JMS\Serializer\Annotation\ExclusionPolicy;
/**
* Group
*
* @ExclusionPolicy("all")
*/
class Group implements GroupInterface
{
/**
* @Expose
* @var integer
*/
private $id;
/**
* @Expose
* @var string
*/
private $title;
/**
* Relation to privilegesis not explicitly exposed.
* @var Privilege[]
*/
private $privileges;
/**
* Relation to Users not explicitly exposed.
* @var User[]
*/
private $users;
...
资源:http://jmsyst.com/libs/serializer/master/cookbook/exclusion_strategies