[Serializer] Ignore \Traversable in default normalizers. Close #14495.
This commit is contained in:
parent
f6c77ff362
commit
c9bff461bc
@ -127,7 +127,7 @@ class GetSetMethodNormalizer extends AbstractNormalizer
|
||||
*/
|
||||
public function supportsNormalization($data, $format = null)
|
||||
{
|
||||
return is_object($data) && $this->supports(get_class($data));
|
||||
return is_object($data) && !$data instanceof \Traversable && $this->supports(get_class($data));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -43,7 +43,7 @@ class ObjectNormalizer extends AbstractNormalizer
|
||||
*/
|
||||
public function supportsNormalization($data, $format = null)
|
||||
{
|
||||
return is_object($data);
|
||||
return is_object($data) && !$data instanceof \Traversable;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -127,7 +127,7 @@ class PropertyNormalizer extends AbstractNormalizer
|
||||
*/
|
||||
public function supportsNormalization($data, $format = null)
|
||||
{
|
||||
return is_object($data) && $this->supports(get_class($data));
|
||||
return is_object($data) && !$data instanceof \Traversable && $this->supports(get_class($data));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -502,6 +502,11 @@ class GetSetMethodNormalizerTest extends \PHPUnit_Framework_TestCase
|
||||
$this->normalizer->denormalize(array('non_existing' => true), __NAMESPACE__.'\PropertyDummy')
|
||||
);
|
||||
}
|
||||
|
||||
public function testNoTraversableSupport()
|
||||
{
|
||||
$this->assertFalse($this->normalizer->supportsNormalization(new \ArrayObject()));
|
||||
}
|
||||
}
|
||||
|
||||
class GetSetDummy
|
||||
|
@ -429,6 +429,11 @@ class ObjectNormalizerTest extends \PHPUnit_Framework_TestCase
|
||||
$this->normalizer->denormalize(array('non_existing' => true), __NAMESPACE__.'\ObjectDummy')
|
||||
);
|
||||
}
|
||||
|
||||
public function testNoTraversableSupport()
|
||||
{
|
||||
$this->assertFalse($this->normalizer->supportsNormalization(new \ArrayObject()));
|
||||
}
|
||||
}
|
||||
|
||||
class ObjectDummy
|
||||
|
@ -419,6 +419,11 @@ class PropertyNormalizerTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$this->normalizer->normalize($obj, 'any');
|
||||
}
|
||||
|
||||
public function testNoTraversableSupport()
|
||||
{
|
||||
$this->assertFalse($this->normalizer->supportsNormalization(new \ArrayObject()));
|
||||
}
|
||||
}
|
||||
|
||||
class PropertyDummy
|
||||
|
Reference in New Issue
Block a user