With api platform, State Processor returns input DTO regardless of output class or normalization context
Opened this issue · 0 comments
rnbw-spctrm commented
The Api Platform 3 Part 3: Custom Resource course leads to an incomplete setup when using a custom resource with a different input and output format (either distinct DTO classes or when using serialization groups). The 'output' property and the 'normalizationContext' on both the resource and operation are ignored, so POST requests will return the input DTO.
I solved this by mapping to the output DTO and returning this object at the end of the process method in the state processor.
...
class DtoToEntityStateProcessor implements ProcessorInterface
{
...
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): mixed
{
...
return $this->microMapper->map($entity, OutputDto::class, [
MicroMapperInterface::MAX_DEPTH => 1
]);
}
I am posting this here in case anyone runs into the same issue, as this took me multiple days to track down.