protected function streamToDocument(StreamInterface $stream): AbstractDocument
    {
        $content = $stream->getContents();
        $decoded = json_decode($content);

        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new \RuntimeException('Decoding error: "' . json_last_error_msg() . '""');
        }

        return $this->hydrator->hydrate($decoded);
    }