Symfony 4.1.6,序列化类

时间:2018-10-31 05:07:19

标签: symfony symfony4 serializer

序列化与另一个实体有关系的实体时。

如果未设置A circular reference has been detected when serializing the object of classsetCircularReferenceLimit,则会发生

setCircularReferenceHandler

它解决了symfony3.2之前的问题,但是现在Symofony4.1.6 Error: Maximum execution time of 30 seconds exceeded发生了,并且超时了。

我应该在哪里检查????

$encoders = array(new XmlEncoder(), new JsonEncoder());
$norm = new ObjectNormalizer();

//// it fixes the problem before Symfony 3.2, but no it causes timeout
$norm->setCircularReferenceLimit(0);
$norm->setCircularReferenceHandler(function ($object) {
     return $object->getId();
});
//////////

$normalizers = array($norm);
$serializer = new Serializer($normalizers, $encoders);

/// get entity from doctorine2//
$myEntity = .... 

$jsonContent = $serializer->serialize($myEntity, 'json');

我的错误是

in vendor/symfony/property-access/PropertyAccessor.php (line 372)

    $result = self::$resultProto;        
    $object = $zval[self::VALUE];        
    $access = $this->getReadAccessInfo(\get_class($object), $property); 

    if (self::ACCESS_TYPE_METHOD === $access[self::ACCESS_TYPE]) {            
    $result[self::VALUE] = $object->{$access[self::ACCESS_NAME]}();
    } elseif (self::ACCESS_TYPE_PROPERTY === $access[self::ACCESS_TYPE]) {            
        $result[self::VALUE] = $object->{$access[self::ACCESS_NAME]};


    if ($access[self::ACCESS_REF] && isset($zval[self::REF])) {                
    $result[self::REF] = &$object->{$access[self::ACCESS_NAME]};

0 个答案:

没有答案