{"record":{"id":"45295a30bc824dfa","repo":"symfony/http-kernel","slug":"request-payload-contains-invalid-s-data","errorCode":null,"errorMessage":"Request payload contains invalid \"%s\" data.","messagePattern":"Request payload contains invalid \"(.+?)\" data\\.","errorType":"http","errorClass":"BadRequestHttpException","httpStatus":400,"severity":"error","filePath":"Controller/ArgumentResolver/RequestPayloadValueResolver.php","lineNumber":288,"sourceCode":"            default => $argument->getType(),\n        };\n\n        if (\\is_array($data)) {\n            $data = $this->mergeParamsAndFiles($data, $request->files->all());\n\n            return $this->serializer->denormalize($data, $type, self::hasNonStringScalar($data) ? $format : 'csv', $attribute->serializationContext + self::CONTEXT_DENORMALIZE + ('form' === $format ? ['filter_bool' => true] : []));\n        }\n\n        if ('form' === $format) {\n            throw new BadRequestHttpException('Request payload contains invalid \"form\" data.');\n        }\n\n        try {\n            return $this->serializer->deserialize($data, $type, $format, self::CONTEXT_DESERIALIZE + $attribute->serializationContext);\n        } catch (UnsupportedFormatException $e) {\n            throw new UnsupportedMediaTypeHttpException(\\sprintf('Unsupported format: \"%s\".', $format), $e);\n        } catch (NotEncodableValueException $e) {\n            throw new BadRequestHttpException(\\sprintf('Request payload contains invalid \"%s\" data.', $format), $e);\n        } catch (UnexpectedPropertyException $e) {\n            throw new BadRequestHttpException(\\sprintf('Request payload contains invalid \"%s\" property.', $e->property), $e);\n        }\n    }\n\n    private function mapUploadedFile(Request $request, ArgumentMetadata $argument, MapUploadedFile $attribute): UploadedFile|array|null\n    {\n        if ($files = $request->files->get($attribute->name ?? $argument->getName())) {\n            return !\\is_array($files) && $argument->isVariadic() ? [$files] : $files;\n        }\n\n        if ($argument->isNullable() || $argument->hasDefaultValue()) {\n            return null;\n        }\n\n        return 'array' === $argument->getType() ? [] : null;\n    }\n","sourceCodeStart":270,"sourceCodeEnd":306,"githubUrl":"https://github.com/symfony/http-kernel/blob/aa3a39d7286a62cdfea98f0e69c651a3da6e36cf/Controller/ArgumentResolver/RequestPayloadValueResolver.php#L270-L306","documentation":"During #[MapRequestPayload] deserialization, a NotEncodableValueException means the request body could not be decoded into a PHP structure in the request's format - typically malformed JSON/XML. Symfony rethrows it as a 400 BadRequestHttpException with the format named in the message. It tells the client their payload is syntactically invalid.","triggerScenarios":"Sending invalid JSON (trailing commas, unquoted keys, truncated body, wrong encoding) with Content-Type: application/json to a controller using #[MapRequestPayload]; malformed XML for xml Content-Type; empty body where one is required.","commonSituations":"Hand-rolled clients concatenating JSON strings; broken template interpolation producing invalid JSON; request bodies cut off by proxies or body size limits; BOM or charset issues in the payload.","solutions":["Validate the client payload with a JSON linter/JSON.parse before sending.","Ensure Content-Type matches the actual body format (don't send XML with application/json).","Check for body truncation: raise proxy/web-server body limits or reduce payload size.","Serialize with a real JSON library rather than string concatenation."],"exampleFix":"// before: invalid JSON with trailing comma\n'{\"name\":\"John\",}'\n// after\n'{\"name\":\"John\"}'","handlingStrategy":"validation","validationCode":"const body = buildPayload();\nJSON.parse(body); // throws SyntaxError before sending if malformed\nfetch(url, { method: 'POST', headers: {'Content-Type': 'application/json'}, body });","typeGuard":null,"tryCatchPattern":"try {\n    $result = $api->submit($payload);\n} catch (BadRequestHttpException $e) {\n    $logger->error('Payload rejected as malformed', ['previous' => $e->getPrevious()?->getMessage()]);\n    // fix and resend the payload\n}","preventionTips":["Always serialize payloads with a real JSON encoder, never string concatenation.","Validate bodies with a linter/JSON schema in tests.","Check for proxies or size limits truncating request bodies."],"tags":["symfony","http-kernel","bad-request","json","deserialization"],"backgroundTag":"json-decode-failed","analyzedSha":"aa3a39d7286a62cdfea98f0e69c651a3da6e36cf","analyzedAt":"2026-09-13T18:03:36.509Z","contentChangedAt":"2026-09-13T18:03:36.509Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}