public function withMediaType(string $mediaType): self
    {
        if (!$encoding = $this->api->getEncodings()->find($mediaType)) {
            throw new \InvalidArgumentException(
                "Media type {$mediaType} is not valid for API {$this->api->getName()}."
            );
        }

        $codec = $this->factory->createCodec(
            $this->api->getContainer(),
            $encoding,
            null
        );

        return $this->withCodec($codec);
    }