Skip to content

MapTo('array', property:'rename') should skip the default name #238

@GromNaN

Description

@GromNaN

I'm trying to map a class to an array, renaming some fields.

class MyModel {
    #[MapTo(target: 'array', property: '_id')]
    public string $id;
}

$myModel = new MyModel;
$myModel->id = 'foo';

$automapper->map($myModel, 'array');

The result contains both _id and id, but I only want _id.

[
    '_id' => 'foo',
    'id' => 'foo',
]

If I add the #[Symfony\Component\Serializer\Attribute\Ignore] attribute, the id property is excluded, but that also excludes from the API Platform serializer.

When a #[MapTo] attribute is set, should the default name be skipped?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions