[ObjectMapper] Object to Object mapper component#51741
Merged
fabpot merged 1 commit intosymfony:7.3from Mar 24, 2025
Merged
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why ?
In the train back from API Platform Con and after watching @weaverryan conference about API Platform's feature that helps separating Doctrine Entities from POPOs, we had the feeling that such a component is definitely missing from the Symfony ecosystem. Current implementations (automapper-plus, janephp/automapper) are good but feel to complicated when you want something accessible (DX and complexity). Here we're not trying to have exceptional performance, we just want an accessible API with few mandatory features. Basically those are:
Map(target: A::class))Map(target: 'prop'))Map(transform: 'ucfirst'))Map(if: 'boolval'))Other implementation details:
The rest is not "auto".
Mapper Component
The Mapper component allows you to map an object to another object,
facilitating the mapping using attributes.
Usage
The
Mapattribute has the following signature:ifandtransformare callable or Symfony services, not that we need to introduce an interface for services to implement, this will follow if we want to introduce the component inside the Framework Bundle.The mapper also takes a
$sourceargument if one needs to update an object instead of creating a new one:TODO
ObjectMappermaxDepthis for serializers.