Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions object_mapper.rst
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,32 @@ And the related target object must define the ``createFromLegacy()`` method::
}
}

Mapping Collections
-------------------

By default, ObjectMapper does not map arrays or traversable collections.
To map each item in a collection (such as an array of DTOs to an array of entities), you **must** use the `MapCollection` transformer explicitly:

Example::

use Symfony\Component\ObjectMapper\Attribute\Map;
use Symfony\Component\ObjectMapper\Transform\MapCollection;

class ProductListInput
{
#[Map(transform: new MapCollection())]
/** @var ProductInput[] */
public array $products;
}

This configuration tells ObjectMapper to map each item in the `products` array using the usual mapping rules.

If you do not add `transform: new MapCollection()`, the array will be mapped as-is.

.. versionadded:: 7.4

The MapCollection component was introduced in Symfony 7.4.

Mapping Multiple Targets
------------------------

Expand Down