diff --git a/src/Metadata/ClassMetadata.php b/src/Metadata/ClassMetadata.php index 63c513c2f..e79e97238 100644 --- a/src/Metadata/ClassMetadata.php +++ b/src/Metadata/ClassMetadata.php @@ -216,7 +216,9 @@ public function merge(MergeableInterface $object): void $this->postDeserializeMethods = array_merge($this->postDeserializeMethods, $object->postDeserializeMethods); $this->xmlRootName = $object->xmlRootName; $this->xmlRootNamespace = $object->xmlRootNamespace; - $this->excludeIf = $object->excludeIf; + if (null !== $object->excludeIf) { + $this->excludeIf = $object->excludeIf; + } $this->xmlNamespaces = array_merge($this->xmlNamespaces, $object->xmlNamespaces); if ($object->accessorOrder) { diff --git a/tests/Fixtures/PersonAccountOnParent.php b/tests/Fixtures/PersonAccountOnParent.php new file mode 100644 index 000000000..31b081382 --- /dev/null +++ b/tests/Fixtures/PersonAccountOnParent.php @@ -0,0 +1,15 @@ +assertEquals($accountNotExpired->name, $deserialized[0]->name); } + public function testExcludeIfOnParentClass() + { + $accountNotExpired = new PersonAccountOnParent(); + $accountNotExpired->name='Not expired account'; + $accountNotExpired->expired = false; + + $accountExpired = new PersonAccountOnParent(); + $accountExpired->name='Expired account'; + $accountExpired->expired = true; + + $accounts = [$accountNotExpired,$accountExpired]; + + $language = new ExpressionLanguage(); + + $builder = SerializerBuilder::create(); + $builder->setExpressionEvaluator(new ExpressionEvaluator($language)); + $serializer = $builder->build(); + + $serialized = $serializer->serialize($accounts, $this->getFormat(), null, sprintf('array<%s>', PersonAccountOnParent::class)); + $deserialized = $serializer->deserialize($serialized, sprintf('array<%s>', PersonAccountOnParent::class), $this->getFormat()); + + $this->assertEquals(1, count($deserialized)); + $this->assertEquals($accountNotExpired->name, $deserialized[0]->name); + } + public function testExpressionExclusionNotConfigured() { $person = new PersonSecret();