Skip to content

[ObjectMapper] Support mapping to nested arrays of objects #61116

@crtl

Description

@crtl

Description

Nested mapping is currently only supported for a single object.
Theres currently no way without implementing it yourself using reflection to map array of objects to an array of targets.

Example

// Test source object
class Book {
  /**
    * @var Page[]
    */
  protected array $pages;
}

// Test dto
#[Map(source: Book::class)]
class BookDto {

  /**
   * @var PageDto[]
   */
  #[Map(source: "pages")]
  public array $pages;

}

// Mapping Book to BookDto
$book = new Book();
$dto = $mapper->map($book, BookDto::class);
var_dump($dto->pages); // Page[]

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