public <T> Optional<T> optional(final Object[] params, final int index, final Class<T> paramClass)
      throws JsonRpcParameterException {
    if (params == null || params.length <= index || params[index] == null) {
      return Optional.empty();
    }

    final T param;
    final Object rawParam = params[index];
    if (paramClass.isAssignableFrom(rawParam.getClass())) {
      // If we're dealing with a simple type, just cast the value
      param = paramClass.cast(rawParam);
    } else {
      // Otherwise, serialize param back to json and then deserialize to the paramClass type
      try {
        final String json = mapper.writeValueAsString(rawParam);
        param = mapper.readValue(json, paramClass);
      } catch (final JsonProcessingException e) {
        throw new JsonRpcParameterException(
            String.format(
                "Invalid json rpc parameter at index %d. Supplied value was: '%s' of type: '%s' - expected type: '%s'",
                index, rawParam, rawParam.getClass().getName(), paramClass.getName()),
            e);
      }
    }

    return Optional.of(param);
  }
Retrieves an optional parameter at the given index interpreted as the given class. Throws
InvalidJsonRpcParameters if parameter is of the wrong type.

@param params the list of objects from which to extract a typed object.
@param index Which index of the params array to access.
@param paramClass What type is expected at this index.
@param <T> The type of parameter.
@return Returns the parameter cast as T if available.
ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonRpcParameter.java