diff --git a/src/JMS/Serializer/Metadata/ClassMetadata.php b/src/JMS/Serializer/Metadata/ClassMetadata.php index 3d76f2563..bd874ba20 100644 --- a/src/JMS/Serializer/Metadata/ClassMetadata.php +++ b/src/JMS/Serializer/Metadata/ClassMetadata.php @@ -167,6 +167,12 @@ public function merge(MergeableInterface $object) $this->discriminatorDisabled = $object->discriminatorDisabled; } + if ($object->discriminatorMap) { + $this->discriminatorFieldName = $object->discriminatorFieldName; + $this->discriminatorMap = $object->discriminatorMap; + $this->discriminatorBaseClass = $object->discriminatorBaseClass; + } + if ($this->discriminatorMap && ! $this->reflection->isAbstract()) { if (false === $typeValue = array_search($this->name, $this->discriminatorMap, true)) { throw new \LogicException(sprintf( diff --git a/tests/JMS/Serializer/Tests/Serializer/Doctrine/IntegrationTest.php b/tests/JMS/Serializer/Tests/Serializer/Doctrine/IntegrationTest.php index b420db465..c497a56e3 100644 --- a/tests/JMS/Serializer/Tests/Serializer/Doctrine/IntegrationTest.php +++ b/tests/JMS/Serializer/Tests/Serializer/Doctrine/IntegrationTest.php @@ -24,6 +24,7 @@ use JMS\Serializer\Tests\Fixtures\Doctrine\SingleTableInheritance\Student; use JMS\Serializer\Tests\Fixtures\Doctrine\SingleTableInheritance\Teacher; use JMS\Serializer\Tests\Fixtures\Doctrine\SingleTableInheritance\School; +use JMS\Serializer\Tests\Fixtures\Doctrine\SingleTableInheritance\Organization; class IntegrationTest extends \PHPUnit_Framework_TestCase { @@ -38,6 +39,9 @@ public function testDiscriminatorIsInferredForEntityBaseClass() $school = new School(); $json = $this->serializer->serialize($school, 'json'); $this->assertEquals('{"type":"school"}', $json); + + $deserialized = $this->serializer->deserialize($json, Organization::class, 'json'); + $this->assertEquals($school, $deserialized); } public function testDiscriminatorIsInferredForGenericBaseClass() @@ -45,6 +49,9 @@ public function testDiscriminatorIsInferredForGenericBaseClass() $student = new Student(); $json = $this->serializer->serialize($student, 'json'); $this->assertEquals('{"type":"student"}', $json); + + $deserialized = $this->serializer->deserialize($json, Person::class, 'json'); + $this->assertEquals($student, $deserialized); } public function testDiscriminatorIsInferredFromDoctrine()