-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Description
Symfony version(s) affected
7.2.3
Description
We have a DTO that needs to be mapped to a Resource Object, using target-Attributes inside the DTO.
The DTO has a nested object, which isn't handled by the object mapper.
How to reproduce
#[Map(target: BankDataResource::class)]
class BankDataDto
{
#[Map(target: 'iban')
public string $iban;
public BankDto $bank;
}
class BankDto
{
#[Map(target: 'bic')
public string $bic;
#[Map(target: 'bankCode')
public string $code;
#[Map(target: 'bankName')
public string $name;
}
class BankDataResource
{
public string $iban;
public string $bic;
public string $bankCode;
public string $bankName;
}
// $dto = new BankDataDto();
// ...
$bankdata = $objectMapper->map($dto, BankDataResource::class);
The values from BankDto are not mapped, I tried a lot of different attribute configurations. And the docs don't say anything about this. But I think this should be possible.
Right now I do this ugly version to get my result:
// $dto = new BankDataDto();
// ...
$bankdata = $objectMapper->map($dto, BankDataResource::class);
$bankdata = $objectMapper->map($dto->bank, $bankdata);
But this feels counterintuitive...
Possible Solution
It should be possible to give the mapper a hint to handle sub-objects.
Additional Context
No response
daFish and rvanlaak