diff --git a/CHANGELOG.md b/CHANGELOG.md index 303a52b1..6937fd82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,8 @@ * fix: mapping to object extending `stdClass` to property with no setter. * feat: `stdClass` to `stdClass` mapping should work correctly. * feat: Mapping to existing values in a dynamic property. +* perf(`ObjectToObjectTransformer`): Prevent delegating to `MainTransformer` if + the current value in a dynamic property is a scalar. ## 1.0.0 diff --git a/src/Transformer/Implementation/ObjectToObjectTransformer.php b/src/Transformer/Implementation/ObjectToObjectTransformer.php index ff9aaf6b..8bd70c57 100644 --- a/src/Transformer/Implementation/ObjectToObjectTransformer.php +++ b/src/Transformer/Implementation/ObjectToObjectTransformer.php @@ -587,7 +587,10 @@ private function mapDynamicProperties( } - if ($currentTargetPropertyValue === null) { + if ( + $currentTargetPropertyValue === null + || is_scalar($currentTargetPropertyValue) + ) { /** @psalm-suppress MixedAssignment */ $targetPropertyValue = $sourcePropertyValue; } else {