Skip to content

object mapper with multiple resources using the same entity #7310

Description

@mrossard

API Platform version(s) affected: v4.2.0-alpha.1

Description
When you have multiple resources using the same entityClass, the ObjectMapperProvider doesn't pick the correct one (always converts the entity to the same resource class).

How to reproduce

#[ApiResource(
    stateOptions: new Options(entityClass: TestEntity::class)
)]
#[Map(target: TestEntity::class)]
class TestResource
//...

#[ApiResource(
    stateOptions: new Options(entityClass: TestEntity::class)
)]
#[Map(target: TestEntity::class)]
class SecondTestResource
//...

#[ORM\Entity(repositoryClass: TestEntityRepository::class)]
#[Map(target: TestResource::class,)]
#[Map(target: SecondTestResource::class)]
class TestEntity

Possible Solution
Have the ObjectMapperProvider use the operation class as the target in the call to objectMapper->map()

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