public function encodeJson($data): string
    {
        if ($data instanceof JsonSerializable) {
            $data = $data->jsonSerialize();
        }

        $result = json_encode($this->utf8Encoding->encodeUtf8($data), 512, JSON_THROW_ON_ERROR);

        if ($result === false) {
            throw new JsonException('Json encoding failed');
        }

        return $result;
    }