public function encode($value, $optionsMask = 0)
    {
        $encoded = json_encode($value, $optionsMask);

        $lastError = json_last_error();

        if ($lastError !== JSON_ERROR_NONE) {
            throw new JsonException($this->translateErrorMessage($lastError));
        }

        return $encoded;
    }