Skip to content

[ObjectMapper] Add support to map flat properties to target's nested objects #62439

@siggidiel

Description

@siggidiel

Description

Hey guys. I can't find a way how to map flat properties of my source DTO into my entity class which contains Embeddable properties.

I don't want to implement a custom ObjectMapperMetadataFactoryInterface to add a custom mapping strategy, as this will over-complicate things in our code. Any idea if this is possible or is this a new feature?

Example:

// My source DTO
readonly class UserDto
{
    public function __construct(
        #[Map(target: 'address.zipcode')] public bool $userAddressZipcode,
        #[Map(target: 'address.city')] public bool $userAddressCity
    ) {
    }
}
// Target User entity
class User
{
    #[ORM\Embedded(Address::class)]
    private Address $address
}
// Some controller
public function doStuff(UserDto $dto) 
{
    $this->objectMapper->map(source: $dto, target: User::class);
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions