From 830ca4d793d5a92902f8d5920c7169cf48fb8940 Mon Sep 17 00:00:00 2001 From: soyuka Date: Tue, 16 Dec 2025 15:43:06 +0100 Subject: [PATCH] fix(state): delete with stateOptions and object mapper fixes #7612 --- src/State/Processor/ObjectMapperProcessor.php | 5 +++++ tests/Functional/MappingTest.php | 3 +++ 2 files changed, 8 insertions(+) diff --git a/src/State/Processor/ObjectMapperProcessor.php b/src/State/Processor/ObjectMapperProcessor.php index 2f542d276d..7c71d3e3f0 100644 --- a/src/State/Processor/ObjectMapperProcessor.php +++ b/src/State/Processor/ObjectMapperProcessor.php @@ -56,6 +56,11 @@ public function process(mixed $data, Operation $operation, array $uriVariables = $context, ); + // in some cases (delete operation), the decoration may return a null object + if (null === $persisted) { + return $persisted; + } + $request?->attributes->set('persisted_data', $persisted); // return the Resource representation of the persisted entity diff --git a/tests/Functional/MappingTest.php b/tests/Functional/MappingTest.php index 28f68418c6..70281544ce 100644 --- a/tests/Functional/MappingTest.php +++ b/tests/Functional/MappingTest.php @@ -95,6 +95,9 @@ public function testShouldMapBetweenResourceAndEntity(): void $r = self::createClient()->request('PATCH', $uri, ['json' => ['username' => 'ba zar'], 'headers' => ['content-type' => 'application/merge-patch+json']]); $this->assertJsonContains(['username' => 'ba zar']); + + $r = self::createClient()->request('DELETE', $uri); + $this->assertResponseStatusCodeSame(204); } public function testShouldMapToTheCorrectResource(): void