def to_json
      loop do
        begin
          json = @payload.to_json
        rescue *JSON_EXCEPTIONS => ex
          @config.logger.debug("#{LOG_LABEL} `notice.to_json` failed: #{ex.class}: #{ex}")
        else
          return json if json && json.bytesize <= MAX_NOTICE_SIZE
        end

        break if truncate == 0
      end
    end
def to_json
      loop do
        begin
          json = @payload.to_json
        rescue *JSON_EXCEPTIONS => ex
          @config.logger.debug("#{LOG_LABEL} `notice.to_json` failed: #{ex.class}: #{ex}")
        else
          return json if json && json.bytesize <= MAX_NOTICE_SIZE
        end

        break if truncate == 0
      end
    end
Converts the notice to JSON. Calls +to_json+ on each object inside
 notice's payload. Truncates notices, JSON representation of which is
 bigger than {MAX_NOTICE_SIZE}.

 @return [Hash{String=>String}, nil]