Skip to content

Commit e928051

Browse files
committed
bug symfony#54505 [Serializer]  initialize serializer in trait with null (xabbuh)
This PR was merged into the 7.0 branch. Discussion ---------- [Serializer]  initialize serializer in trait with null | Q | A | ------------- | --- | Branch? | 7.0 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix symfony#54417 | License | MIT Commits ------- dae3726 initialize serializer in trait with null
2 parents 41afede + dae3726 commit e928051

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/Symfony/Component/Serializer/SerializerAwareTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
trait SerializerAwareTrait
1818
{
19-
protected SerializerInterface $serializer;
19+
protected ?SerializerInterface $serializer = null;
2020

2121
public function setSerializer(SerializerInterface $serializer): void
2222
{

src/Symfony/Component/Serializer/Tests/Normalizer/ObjectNormalizerTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,16 @@ public function testSamePropertyAsMethodWithMethodSerializedName()
885885

886886
$this->assertSame($expected, $this->normalizer->normalize($object));
887887
}
888+
889+
public function testNormalizeWithoutSerializerSet()
890+
{
891+
$normalizer = new ObjectNormalizer(new ClassMetadataFactory(new AttributeLoader()));
892+
893+
$this->expectException(LogicException::class);
894+
$this->expectExceptionMessage('Cannot normalize attribute "foo" because the injected serializer is not a normalizer.');
895+
896+
$normalizer->normalize(new ObjectConstructorDummy([], [], []));
897+
}
888898
}
889899

890900
class ProxyObjectDummy extends ObjectDummy

0 commit comments

Comments
 (0)