Skip to content

Commit

Permalink
bug #54505 [Serializer]  initialize serializer in trait with null (xa…
Browse files Browse the repository at this point in the history
…bbuh)

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 #54417
| License       | MIT

Commits
-------

dae3726 initialize serializer in trait with null
  • Loading branch information
chalasr committed Apr 6, 2024
2 parents 41afede + dae3726 commit e928051
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Symfony/Component/Serializer/SerializerAwareTrait.php
Expand Up @@ -16,7 +16,7 @@
*/
trait SerializerAwareTrait
{
protected SerializerInterface $serializer;
protected ?SerializerInterface $serializer = null;

public function setSerializer(SerializerInterface $serializer): void
{
Expand Down
Expand Up @@ -885,6 +885,16 @@ public function testSamePropertyAsMethodWithMethodSerializedName()

$this->assertSame($expected, $this->normalizer->normalize($object));
}

public function testNormalizeWithoutSerializerSet()
{
$normalizer = new ObjectNormalizer(new ClassMetadataFactory(new AttributeLoader()));

$this->expectException(LogicException::class);
$this->expectExceptionMessage('Cannot normalize attribute "foo" because the injected serializer is not a normalizer.');

$normalizer->normalize(new ObjectConstructorDummy([], [], []));
}
}

class ProxyObjectDummy extends ObjectDummy
Expand Down

0 comments on commit e928051

Please sign in to comment.