Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion src/State/Processor/ObjectMapperInputProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProcessorInterface;
use ApiPlatform\State\Util\StateOptionsTrait;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\ObjectMapper\ObjectMapperInterface;

Expand All @@ -25,6 +26,8 @@
*/
final class ObjectMapperInputProcessor implements ProcessorInterface
{
use StateOptionsTrait;

/**
* @param ProcessorInterface<mixed,mixed>|null $decorated
*/
Expand All @@ -51,7 +54,8 @@ public function process(mixed $data, Operation $operation, array $uriVariables =
}

$request = $context['request'] ?? null;
$mapped = $this->objectMapper->map($data, $request?->attributes->get('mapped_data'));
$mapped = $this->objectMapper->map($data, $request?->attributes->get('mapped_data') ?? $this->getStateOptionsClass($operation, $operation->getClass()));
$request?->attributes->set('mapped_data', $mapped);

return $this->decorated ? $this->decorated->process($mapped, $operation, $uriVariables, $context) : $mapped;
}
Expand Down
1 change: 1 addition & 0 deletions tests/Fixtures/TestBundle/ApiResource/MappedResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
stateOptions: new Options(entityClass: MappedEntity::class),
normalizationContext: [ContextBuilder::HYDRA_CONTEXT_HAS_PREFIX => false],
)]
#[Map(target: UnexpectedMappingTarget::class)]
#[Map(target: MappedEntity::class)]
final class MappedResource
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace ApiPlatform\Tests\Fixtures\TestBundle\ApiResource;

class UnexpectedMappingTarget
{

}
Loading