Skip to content

Commit 122c2b0

Browse files
committed
[Serializer] Ignore \Traversable in default normalizers. Close #14495.
1 parent 27e7dc7 commit 122c2b0

File tree

6 files changed

+18
-3
lines changed

6 files changed

+18
-3
lines changed

Normalizer/GetSetMethodNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public function denormalize($data, $class, $format = null, array $context = arra
127127
*/
128128
public function supportsNormalization($data, $format = null)
129129
{
130-
return is_object($data) && $this->supports(get_class($data));
130+
return is_object($data) && !$data instanceof \Traversable && $this->supports(get_class($data));
131131
}
132132

133133
/**

Normalizer/ObjectNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function __construct(ClassMetadataFactoryInterface $classMetadataFactory
4343
*/
4444
public function supportsNormalization($data, $format = null)
4545
{
46-
return is_object($data);
46+
return is_object($data) && !$data instanceof \Traversable;
4747
}
4848

4949
/**

Normalizer/PropertyNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public function denormalize($data, $class, $format = null, array $context = arra
127127
*/
128128
public function supportsNormalization($data, $format = null)
129129
{
130-
return is_object($data) && $this->supports(get_class($data));
130+
return is_object($data) && !$data instanceof \Traversable && $this->supports(get_class($data));
131131
}
132132

133133
/**

Tests/Normalizer/GetSetMethodNormalizerTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,11 @@ public function testDenormalizeNonExistingAttribute()
502502
$this->normalizer->denormalize(array('non_existing' => true), __NAMESPACE__.'\PropertyDummy')
503503
);
504504
}
505+
506+
public function testNoTraversableSupport()
507+
{
508+
$this->assertFalse($this->normalizer->supportsNormalization(new \ArrayObject()));
509+
}
505510
}
506511

507512
class GetSetDummy

Tests/Normalizer/ObjectNormalizerTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,11 @@ public function testDenormalizeNonExistingAttribute()
429429
$this->normalizer->denormalize(array('non_existing' => true), __NAMESPACE__.'\ObjectDummy')
430430
);
431431
}
432+
433+
public function testNoTraversableSupport()
434+
{
435+
$this->assertFalse($this->normalizer->supportsNormalization(new \ArrayObject()));
436+
}
432437
}
433438

434439
class ObjectDummy

Tests/Normalizer/PropertyNormalizerTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,11 @@ public function testUnableToNormalizeObjectAttribute()
419419

420420
$this->normalizer->normalize($obj, 'any');
421421
}
422+
423+
public function testNoTraversableSupport()
424+
{
425+
$this->assertFalse($this->normalizer->supportsNormalization(new \ArrayObject()));
426+
}
422427
}
423428

424429
class PropertyDummy

0 commit comments

Comments
 (0)