symfony/http-kernel · error · UnsupportedMediaTypeHttpException

Unsupported format: " ".

Error message

Unsupported format: "%s".

What it means

When #[MapRequestPayload] deserializes the request body, a serializer UnsupportedFormatException means the requested format (from the Content-Type, e.g. xml, yaml) has no registered encoder/decoder. Symfony converts this into a 415 UnsupportedMediaTypeHttpException. The library throws it so clients get a standard 415 instead of an opaque serializer error.

Solutions

  1. Make the client send a supported Content-Type (usually application/json).
  2. Register the missing encoder in framework.yaml (e.g. enable xml: true under framework.serializer or install symfony/serializer-pack).
  3. Check the route/format negotiation (listener Accept/Content-Type mapping) if you rely on _format.
  4. If the format is genuinely unsupported, return 415 documentation and let clients know which media types are accepted.

Example fix

# before: only json enabled
# after: enable xml encoder
framework:
    serializer:
        enabled: true
# and install symfony/serializer + symfony/property-access encoders
Defensive patterns

Strategy: validation

Validate before calling

$supported = ['json', 'xml']; // formats with registered encoders
$format = $request->getContentTypeFormat();
if ($format !== null && !in_array($format, $supported, true)) {
    // avoid calling the endpoint with this format
}

Try / catch

try {
    $result = $api->callWithPayload($dto);
} catch (UnsupportedMediaTypeHttpException $e) {
    $logger->warning('Unsupported Content-Type sent', ['ct' => $request->headers->get('Content-Type')]);
    return new Response('Unsupported media type', 415);
}

Prevention

When it happens

Trigger: A controller using #[MapRequestPayload] receives a request whose Content-Type maps to a format for which no serializer encoder is configured - e.g. Content-Type: application/xml without the serializer XML encoder enabled, or an exotic Content-Type like text/csv without the CSV encoder registered.

Common situations: Missing/removed encoder package or framework config (framework.serializer encoders); clients sending Content-Type the API never supported; Symfony version upgrades where default encoders changed; typos in Content-Type headers.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of symfony/http-kernel@aa3a39d728 (2026-09-13). Data as JSON: /api/errors/2940e461a9dc66c7. Report an issue: GitHub.

Appendix: source

Thrown at Controller/ArgumentResolver/RequestPayloadValueResolver.php:286

            $argument->isVariadic() => ($attribute->type ?? $argument->getType()).'[]',
            'array' === $argument->getType() && null !== $attribute->type => $attribute->type.'[]',
            default => $argument->getType(),
        };

        if (\is_array($data)) {
            $data = $this->mergeParamsAndFiles($data, $request->files->all());

            return $this->serializer->denormalize($data, $type, self::hasNonStringScalar($data) ? $format : 'csv', $attribute->serializationContext + self::CONTEXT_DENORMALIZE + ('form' === $format ? ['filter_bool' => true] : []));
        }

        if ('form' === $format) {
            throw new BadRequestHttpException('Request payload contains invalid "form" data.');
        }

        try {
            return $this->serializer->deserialize($data, $type, $format, self::CONTEXT_DESERIALIZE + $attribute->serializationContext);
        } catch (UnsupportedFormatException $e) {
            throw new UnsupportedMediaTypeHttpException(\sprintf('Unsupported format: "%s".', $format), $e);
        } catch (NotEncodableValueException $e) {
            throw new BadRequestHttpException(\sprintf('Request payload contains invalid "%s" data.', $format), $e);
        } catch (UnexpectedPropertyException $e) {
            throw new BadRequestHttpException(\sprintf('Request payload contains invalid "%s" property.', $e->property), $e);
        }
    }

    private function mapUploadedFile(Request $request, ArgumentMetadata $argument, MapUploadedFile $attribute): UploadedFile|array|null
    {
        if ($files = $request->files->get($attribute->name ?? $argument->getName())) {
            return !\is_array($files) && $argument->isVariadic() ? [$files] : $files;
        }

        if ($argument->isNullable() || $argument->hasDefaultValue()) {
            return null;
        }

        return 'array' === $argument->getType() ? [] : null;

View on GitHub (pinned to aa3a39d728)