Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 38747ae

Browse filesBrowse files
committed
Merge branch '5.4' into 6.3
* 5.4: [Serializer] Looking for DiscriminatorMap on interfaces when the current object also extends from a class
2 parents 7a2b5f2 + 9271349 commit 38747ae
Copy full SHA for 38747ae

File tree

Expand file treeCollapse file tree

4 files changed

+37
-2
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+37
-2
lines changed

‎src/Symfony/Component/Serializer/Mapping/ClassDiscriminatorFromClassMetadata.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Mapping/ClassDiscriminatorFromClassMetadata.php
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ private function resolveMappingForMappedObject(object|string $object): ?ClassDis
6565
{
6666
$reflectionClass = new \ReflectionClass($object);
6767
if ($parentClass = $reflectionClass->getParentClass()) {
68-
return $this->getMappingForMappedObject($parentClass->getName());
68+
if (null !== ($parentMapping = $this->getMappingForMappedObject($parentClass->getName()))) {
69+
return $parentMapping;
70+
}
6971
}
7072

7173
foreach ($reflectionClass->getInterfaceNames() as $interfaceName) {

‎src/Symfony/Component/Serializer/Tests/Fixtures/DummyMessageInterface.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Tests/Fixtures/DummyMessageInterface.php
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
/**
1717
* @DiscriminatorMap(typeProperty="type", mapping={
1818
* "one"="Symfony\Component\Serializer\Tests\Fixtures\DummyMessageNumberOne",
19-
* "two"="Symfony\Component\Serializer\Tests\Fixtures\DummyMessageNumberTwo"
19+
* "two"="Symfony\Component\Serializer\Tests\Fixtures\DummyMessageNumberTwo",
20+
* "three"="Symfony\Component\Serializer\Tests\Fixtures\DummyMessageNumberThree"
2021
* })
2122
*
2223
* @author Samuel Roze <samuel.roze@gmail.com>
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Serializer\Tests\Fixtures;
13+
14+
/**
15+
* @author Samuel Roze <samuel.roze@gmail.com>
16+
*/
17+
class DummyMessageNumberThree extends \stdClass implements DummyMessageInterface
18+
{
19+
}

‎src/Symfony/Component/Serializer/Tests/SerializerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Tests/SerializerTest.php
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
use Symfony\Component\Serializer\Tests\Fixtures\DummyFirstChildQuux;
5555
use Symfony\Component\Serializer\Tests\Fixtures\DummyMessageInterface;
5656
use Symfony\Component\Serializer\Tests\Fixtures\DummyMessageNumberOne;
57+
use Symfony\Component\Serializer\Tests\Fixtures\DummyMessageNumberThree;
5758
use Symfony\Component\Serializer\Tests\Fixtures\DummyMessageNumberTwo;
5859
use Symfony\Component\Serializer\Tests\Fixtures\DummyObjectWithEnumConstructor;
5960
use Symfony\Component\Serializer\Tests\Fixtures\DummyObjectWithEnumProperty;
@@ -485,6 +486,18 @@ public function testDeserializeAndSerializeNestedInterfacedObjectsWithTheClassMe
485486
$this->assertEquals($example, $deserialized);
486487
}
487488

489+
public function testDeserializeAndSerializeNestedAbstractAndInterfacedObjectsWithTheClassMetadataDiscriminator()
490+
{
491+
$example = new DummyMessageNumberThree();
492+
493+
$serializer = $this->serializerWithClassDiscriminator();
494+
495+
$serialized = $serializer->serialize($example, 'json');
496+
$deserialized = $serializer->deserialize($serialized, DummyMessageInterface::class, 'json');
497+
498+
$this->assertEquals($example, $deserialized);
499+
}
500+
488501
public function testExceptionWhenTypeIsNotKnownInDiscriminator()
489502
{
490503
try {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.