Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
Open
Description
Symfony version(s) affected
7.3.0-BETA2
Description
Hello!
I have been trying to use the ObjectMapper to map my object from one to another using source mapping.
However, it appears that the if condition is not taken into account.
It works fine when using target mapping.
How to reproduce
I want to map my TestDTO to my TestResource but my DTO shouldn't have knowledge about my resource, that's why source mapping is used.
// TestResource.php#[Map( source: TestDTO::class,)]class TestResource{publicstring$id; #[Map(if:false)]public ?string$description =null;}
class TestDTO{publicstring$id;}
$testDTO =newTestDTO();$testDTO->id ='123';$testResource =$this->objectMapper->map($testDTO, TestResource::class);
By using this code I receive the error:
[Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException] Can't get a way to read the property "description" in class "App\DTO\API\TestDTO".
Possible Solution
This is linked to the propertyAccessor used in the getRawValue functionhere. The property doesn't exist in the source, and that's why it doesn't work as intended.
Additional Context
Stacktrace:
Exception trace: at /home/project/vendor/symfony/property-access/PropertyAccessor.php:461 Symfony\Component\PropertyAccess\PropertyAccessor->readProperty() at /home/project/vendor/symfony/property-access/PropertyAccessor.php:102 Symfony\Component\PropertyAccess\PropertyAccessor->getValue() at /home/project/vendor/symfony/object-mapper/ObjectMapper.php:170 Symfony\Component\ObjectMapper\ObjectMapper->getRawValue() at /home/project/vendor/symfony/object-mapper/ObjectMapper.php:124 Symfony\Component\ObjectMapper\ObjectMapper->map() at /home/project/src/Command/TestObjectMapperCommand.php:35 App\Command\TestObjectMapperCommand->execute() at /home/project/vendor/symfony/console/Command/Command.php:318 Symfony\Component\Console\Command\Command->run() at /home/project/vendor/symfony/console/Application.php:1092 Symfony\Component\Console\Application->doRunCommand() at /home/project/vendor/symfony/framework-bundle/Console/Application.php:123 Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at /home/project/vendor/symfony/console/Application.php:341 Symfony\Component\Console\Application->doRun() at /home/project/vendor/symfony/framework-bundle/Console/Application.php:77 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /home/project/vendor/symfony/console/Application.php:192 Symfony\Component\Console\Application->run() at /home/project/vendor/symfony/runtime/Runner/Symfony/ConsoleApplicationRunner.php:49 Symfony\Component\Runtime\Runner\Symfony\ConsoleApplicationRunner->run() at /home/project/vendor/autoload_runtime.php:29 require_once() at /home/project/bin/console:15