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()
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 TestEntityPossible Solution
Have the ObjectMapperProvider use the operation class as the target in the call to objectMapper->map()